Skip to content
Snippets Groups Projects
Commit 2f23e094 authored by jakubs's avatar jakubs
Browse files

BIS-665 SP-1202 make it possible to apply intensity rescale filter on more images

SVN: 30595
parent 2fc2ca12
No related branches found
No related tags found
No related merge requests found
......@@ -438,7 +438,34 @@ public class IntensityRescaling
*/
public static BufferedImage rescaleIntensityLevelTo8Bits(BufferedImage image, Levels levels)
{
return rescaleIntensityLevelTo8Bits(new GrayscalePixels(image), levels);
final int width = image.getWidth();
final int height = image.getHeight();
final BufferedImage rescaledImage =
new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
WritableRaster rescaledRaster = rescaledImage.getRaster();
final float dynamicRange = 255f / (levels.maxLevel - levels.minLevel);
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
for (Channel channel : Channel.values())
{
int originalIntensity = (image.getRGB(x, y) >> channel.getShift()) & 0xff;
// cut all intensities above the white point
int intensity = Math.min(levels.maxLevel, originalIntensity);
// cut all intensities below the black point and move the origin to 0
intensity = Math.max(0, intensity - levels.minLevel);
// normalize to [0, 1] and rescale to 8 bits
intensity = (int) (0.5 + (intensity * dynamicRange));
rescaledRaster.setSample(x, y, channel.getBand(), intensity);
}
}
}
return rescaledImage;
}
public static BufferedImage rescaleIntensityLevelTo8Bits(BufferedImage image, Levels levels,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment