convert Rgb Input To Binary Black And White

Help
Barry NL
2012-05-04
2012-12-24
  • Barry NL
    Barry NL
    2012-05-04

    Hello,

    I have a question regarding the FractionRgbData class of neuroph ImageRecognition. I do not fully understand the implementation of the static FractionRgbData.convertRgbInputToBinaryBlackAndWhite(double inputRGB) method (see a copy of the method below). More specifically, I do not understand why the length of the input array is divided by 3 in the for-loop condition and the for-loop variable i is also incremented with 3 every iteration? I would think dividing the input array by 3 should be enough. Note that the input double array comes from the FractionRgbData.getFlattenedRgbValues() method.

    Hopefully someone can shed some light on this implementation!

    Thanks in advance,

    Barry NL

            /**
             * Converts image rgb data to binary black and white data
             * @param inputRGB flatten rgb data
             * @return binary black and white representation of image
             */
            public static double[] convertRgbInputToBinaryBlackAndWhite(double[] inputRGB) {
                double inputBinary[]= new double[inputRGB.length/3];
                for(int i=0; i<inputRGB.length/3; i+=3) {
                    if (inputRGB[i]>0) inputBinary[i] = 0;
                        else inputBinary[i] = 1;
                }
                return inputBinary;
            }
    
     
  • Zoran Sevarac
    Zoran Sevarac
    2012-05-07

    Hi and thanks for bringing this to our attention. Seems like there is an issue here. Think about the following example:
    We have image 10x10 pixels, that would be 100 image pixels in total where every pixel has RGB color infor thats 100x3=300
    So we need and array of size 300 to store these pixels, and thats inputRGB.

    Next we need binary array which will store binary blac n'  white color info, and that array needs only 100 elements
    In in for loop we might have a bug. The way it  works for our example is:
    for(i=0; i<100; i+=3)

    This takes every third pixel (only RED component!) and it takes only first 33 pixels.
    So it should be

    for(int i=0; i<inputRGB.length; i+=3) {
       if (inputRGB_>0) inputBinary = 0;
         else inputBinary = 1;
    }

    Also the if rule should laso take into account green  and blue components like
    inputRGB
    inputRGB
    and there should be a threshold to say when something is considered to be black or white (not just >0)
    Hope this will help you to come with better implementation, and please share it with us. We'll also deal with this.

    Zoran_

     
  • Elle
    Elle
    2012-05-15

    Hi Folks,

    You could take a look at the FractionHSIData class (assuming it is still in the build, and it is a very old class!). If it is this should do pretty much what you want. It does provide comments as to why the odd array length logic is in there.

    To convert an RGB image into a BW image you could override the class and then use the calculateIntesity() method with as stated above a threshold value to define between white and black.

    Any questions, please just ask me.

    Elle