Skip to content

Commit d5d4a94

Browse files
fix(dataset): remove incorrect BGR2RGB conversion causing color disto… (#151)
PIL's Image.open().convert('RGB') already loads images in RGB format. Applying cv.cvtColor(image, cv.COLOR_BGR2RGB) incorrectly assumes the input is BGR, which swaps the Red and Blue channels. This caused the visualized 'Original' images to appear with a blue/purple tint. Removed the unnecessary OpenCV color conversion to preserve the correct RGB format for matplotlib visualization. ## 🔗 Related Issue Fixes # ## 📝 Description - - - ## 🔄 Type of Change - [x] 🐛 Bug fix (non-breaking change which fixes an issue) - [ ] 🚀 New feature (non-breaking change which adds functionality) - [ ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 📖 Documentation update - [ ] 🏗️ Infrastructure / CI/CD update ## 🧪 Hardware & Matrix Testing **I have successfully built and tested this code using `uv` on:** - [x] `anomavision[cpu]` (Standard/Edge) - [ ] `anomavision[cu121]` (CUDA 12.1) - [ ] `anomavision[cu124]` (CUDA 12.4) - [ ] `anomavision[cu118]` (CUDA 11.8) **Host OS used for testing:** - [ ] Linux / Ubuntu - [ ] Windows (Native or WSL2) - [ ] macOS ## ✅ Developer Checklist - [x] My code follows the core style guidelines of this project (Ruff/Black formatting). - [x] I have run `uv run pytest` and all unit tests pass locally. - [ ] **Lockfile Guard:** If I added or modified a dependency in `pyproject.toml`, I have run `uv lock --python 3.10` and committed the updated `uv.lock` file. - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have updated the documentation accordingly (if applicable). ## 📸 Screenshots / Visual Proof (Optional)
2 parents bf410e6 + 785535b commit d5d4a94

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

anomavision/datasets/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __getitem__(self, idx):
103103
image = Image.open(self.image_paths[idx]).convert("RGB")
104104
batch = self.image_transforms(image)
105105
image = np.array(image)
106-
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
106+
# image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
107107

108108
# Load mask if mask_directory_path argument is given
109109
if self.mask_directory_path is not None:

anomavision/detect.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,10 @@ def run_inference(args):
428428
if config.enable_visualization:
429429
with profilers["visualization"]:
430430
try:
431-
test_images = np.array(images)
432431

433432
boundary_images = (
434433
anomavision.visualization.framed_boundary_images(
435-
test_images,
434+
images,
436435
(
437436
anomavision.classification(
438437
score_maps, config.thresh
@@ -446,7 +445,7 @@ def run_inference(args):
446445
)
447446

448447
heatmap_images = anomavision.visualization.heatmap_images(
449-
test_images,
448+
images,
450449
score_maps,
451450
alpha=config.get("viz_alpha", 0.5),
452451
)

0 commit comments

Comments
 (0)