From d156564b5dfdfa668da9179bc44eb91c468bc6b6 Mon Sep 17 00:00:00 2001
From: tpylak <tpylak>
Date: Tue, 13 Sep 2011 22:54:56 +0000
Subject: [PATCH] LMS-2502 image transformations: minor refactoring

SVN: 22928
---
 .../cisd/common/image/IntensityRescaling.java      | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/common/source/java/ch/systemsx/cisd/common/image/IntensityRescaling.java b/common/source/java/ch/systemsx/cisd/common/image/IntensityRescaling.java
index 21cee41412a..4480fb635b1 100644
--- a/common/source/java/ch/systemsx/cisd/common/image/IntensityRescaling.java
+++ b/common/source/java/ch/systemsx/cisd/common/image/IntensityRescaling.java
@@ -125,7 +125,7 @@ public class IntensityRescaling
      */
     public static int computeBitShift(BufferedImage image, float threshold)
     {
-        if (image.getColorModel().getColorSpace().getNumComponents() > 1)
+        if (isNotGrayscale(image))
         {
             throw new IllegalArgumentException(
                     "computeBitShift() is only applicable to gray scale images.");
@@ -149,6 +149,12 @@ public class IntensityRescaling
         return getBitShiftLowerThanThreshold(b0, pixels, threshold);
     }
 
+    /** @return true if the specified image in not in grayscale */
+    public static boolean isNotGrayscale(BufferedImage image)
+    {
+        return image.getColorModel().getColorSpace().getNumComponents() > 1;
+    }
+
     /**
      * Performs an intensity rescaling on a gray-scale image by shifting all intensities so that
      * only significant bits are kept. A bit position is considered significant if only a small
@@ -175,7 +181,7 @@ public class IntensityRescaling
      */
     public static BufferedImage rescaleIntensityBitShiftTo8Bits(BufferedImage image, int shiftBits)
     {
-        if (image.getColorModel().getColorSpace().getNumComponents() > 1)
+        if (isNotGrayscale(image))
         {
             throw new IllegalArgumentException(
                     "rescaleIntensityBitShiftTo8Bits() is only applicable to gray scale images.");
@@ -199,7 +205,7 @@ public class IntensityRescaling
      */
     public static void addToLevelStats(PixelHistogram histogram, BufferedImage image)
     {
-        if (image.getColorModel().getColorSpace().getNumComponents() > 1)
+        if (isNotGrayscale(image))
         {
             throw new IllegalArgumentException(
                     "addToLevelStats() is only applicable to gray scale images.");
@@ -274,7 +280,7 @@ public class IntensityRescaling
      */
     public static BufferedImage rescaleIntensityLevelTo8Bits(BufferedImage image, Levels levels)
     {
-        if (image.getColorModel().getColorSpace().getNumComponents() > 1)
+        if (isNotGrayscale(image))
         {
             throw new IllegalArgumentException(
                     "rescaleIntensityLevelTo8Bits() is only applicable to gray scale images.");
-- 
GitLab