I have an grayscale image, in grayscale images, each pixel have a uint8 value. for example when i use myImage(2, 3) , then i received a value between 0 to 255 corresponding pixel value. now i want convert this value to a binary array of 8 bits. for example : if myImage(2, 3) is equivalent to 15, then i want converted value of this pixel be 00001111.
I have an grayscale image, in grayscale images, each pixel have a uint8 value.
Share
dec2bin(15, 8)returns00001111, as a string. Here, 8 specifies the minimum length of the binary string.See here for full info.
If you want it as a matrix, you could do something like this:
Which, with a pixelVal of 15, results in
m = [0 0 0 0 1 1 1 1].