 # Encoder for convert image to binary matrix

hi every one. i read “the HTM Spatial Pooler-A neocortical Algorithm for online Sparse Distributed coding” paper, in this paper the author use some data set like MNIST and …
I like to use one of the images of MNIST to get it to HTM and SP algorithm.but my problem is that image has real value ,but the input of SP in HTM should be binary,what should I do? can you introduce a good encoder to convert image matrix to binary matrix?

Thresholding is one way to do it. It’s a pretty common practice for MNIST, actually.
For example, if a pixel has the value of below 0.5, make it 0. If not, 1.
But if you want to go all the way, you could represent a pixel by N number of bits.
If N = 4, you could represent a pixel by 0011(< 0.33), 0110(< 0.66), or 1100.
This is actually equal to having a scalar encoder for each pixel.

1 Like

Hi @shiva, you may want to view the htm.core project, as it has a working MINST example ready to go. After you build, you can run the example at `build/Release/bin/mnist_sp`.

1 Like

thanks a lot
but can you explain how can i decode the image after threshold?(i mean is there any way to create the image from binary matrix again?)

thanks

thanks
can you say me from which function i should use to decode the image again?

I’m not sure you can decode the image without using a standard ML classifier.

can you explain more?
I want to get image to HTM Spatial pooling so i need to encode image and create SDR, then I want decode the SDR to image,is there any way?

The explanation overlaps something I just posted at here.

Theoretically, encoding is a one-way process. Think about your brain. Encodings come in, but we don’t share our neural codes outside of our own brains to communicate. We developed language to do this.

1 Like

This might not be as effective but regression could be a simple solution.
I think linear regression would be sufficient for a simple problem like MNIST.
(i.e. each pixel in a decoded image is a weighted sum of an output SDR of SP.)   thanks There is a way to take images to and from sparse representations. If the encoding process utilizes a filter bank to obtain the k-best matches to a specific subset of the image, then that portion of the image can be reconstructed (approximately) by reconstructing the patch from a linear combination of the activated filters. All that would be needed is to find a way to store the filter response coefficients (e.g. the scalar coefficients).

One possibility for storing the scalars would be to use a grid-cell-like module to store the scalar response. This has the advantage of allowing the possibility of each of the extracted features (filters) to be manipulated independently to obtain new combinations not previously observed, or to recognize previously observed features (objects) under slightly different observing conditions.

3 Likes