imagej / imagej/ImageJ

MedianCut should scale all color values from [0, 248] -> [0, 255]

Open
#133 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
786
Forks
267
PR merge metrics
No merged PRs in 30d

Description

I did some tests and `MedianCut` tends to make images darker because all colors besides white are with their last 3 bits set to '0'.

> https://github.com/imagej/imagej1/blob/faaa7e0b29e91afff5cba11b8c0e700d9e976ea4/ij/process/MedianCut.java#L253-L254

The following replacement does a much better job:
```
// adjust values, i.e. we had the last 3 bits cut off: [0, 248] --> [0, 255]
r = (255 * r) / 248;
g = (255 * g) / 248;
b = (255 * b) / 248;
```
This also resets white to its original color.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in MedianCut.java at the linked lines 253-254 and inspect how the red, green, and blue values are adjusted after the last three bits are removed. Apply the reported scaling behavior and verify that the resulting colors cover the intended range and preserve white, addressing the darker-image symptom described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
computer-vision
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.