htm.java icon indicating copy to clipboard operation
htm.java copied to clipboard

Add ImageEncoder from nupic.encoders

Open DefinitlyEvil opened this issue 10 years ago • 6 comments

[I removed all the useless words. ] This should be what we working on around, https://github.com/numenta/nupic.vision .

Extra suggestion: adding dependency for JavaCV to faster the processing speed.

DefinitlyEvil avatar Sep 24 '15 13:09 DefinitlyEvil

@DefinitlyEvil Hi, could you point me to the ImageEncoder? I wasn't aware there was one?

Here's the list as I know it...

https://github.com/numenta/nupic/tree/master/src/nupic/encoders

cogmission avatar Sep 24 '15 14:09 cogmission

Hi David, in nupic.vision repo

breznak avatar Sep 24 '15 14:09 breznak

@breznak Thanks! :+1:

@DefinitlyEvil Well then, looks like we have a new mission! 🎉Thanks. I will add this to the list!

cogmission avatar Sep 24 '15 14:09 cogmission

@DefinitlyEvil Editing this issue to make it more specific. This one will be for the ImageEncoder. We can add others as they are required.

cogmission avatar Sep 24 '15 15:09 cogmission

NOTE: L = R * 299/1000 + G * 587/1000 + B * 114/1000 When converting to a bilevel image (mode “1”), the source image is first converted to black and white. Resulting values larger than 127 are then set to white, and the image is dithered. To use other thresholds, use the point method. To disable dithering, use the dither= option (see below).

Upon Researching, Use the following Luma Transform (to transform to grayscale):

void convertToGrayscale(final BufferedImage image){
    for(int i=0; i<image.getWidth(); i++){
        for(int j=0; j<image.getHeight(); j++){
            int color = image.getRGB(i,j);

            int alpha = (color >> 24) & 255;
            int red = (color >> 16) & 255;
            int green = (color >> 8) & 255;
            int blue = (color) & 255;

            final int lum = (int)(0.2126 * red + 0.7152 * green + 0.0722 * blue);

            alpha = (alpha << 24);
            red = (lum << 16);
            green = (lum << 8);
            blue = lum;

            color = alpha + red + green + blue;

            image.setRGB(i,j,color);
        }
    }
}

This will perform the color to Grayscale conversion using the same algorithm as defined in the Python PIL library ( ITU-R 601-2 luma transform )

Looking at the line:

image = image.convert('1',dither=Image.NONE)

From the method below in the image_encoders.py file

def imageToVector(image):
  '''
  Returns a bit vector representation (list of ints) of a PIL image.
  '''
  # Convert the image to black and white
  image = image.convert('1',dither=Image.NONE)
  # Pull out the data, turn that into a list, then a numpy array,
  # then convert from 0 255 space to binary with a threshold.
  # Finally cast the values into a type CPP likes
  vector = (numpy.array(list(image.getdata())) < 100).astype('uint32')

  return vector

cogmission avatar Sep 24 '15 15:09 cogmission

And probably we can use JavaCV for image processing to get better performance.

DefinitlyEvil avatar Sep 24 '15 23:09 DefinitlyEvil