I would like to create a code from a given image. For example, this image:
should get the code 111-111-010
.
(Suppose it's a png
image and all pixels except the banana itself are transparent.)
If all pixels in a particular square are transparent, the value of this square is 0
, otherwise it's 1
.
So, given an image, I would like to divide it to squares of a given size (e.g. the banana image is 300x300
pixels, and the squares are 100x100
), and then to create a code (string) which is built like described above.
The easiest way would probably be by using each_pixel
and just check manually if all pixels in a square are transparent. Is there a better method?