How to construct a binary image based on the most significant bit of the pixels?
Show older comments
The brightness intensity of the image fractal.jpg takes values between 0 and 255.Thus each pixel of the image can be represented with 8 bits.Since we have the image, how can i construct a binary image based on the most significant bit of the pixels.Specifically , if the MSB of a pixel is 1 , the pixel in the new image will take 255 , while if it is 0 ,the pixel in the new image will take value 0 .Repeat for the second most significant bit and the least significant bit (least significant bit, LSB). I have to implement this in Octave.
Accepted Answer
More Answers (1)
Alexandros Ioannidis
on 8 Jun 2015
1 Comment
Image Analyst
on 8 Jun 2015
Not sure what that code is for, but you can do the same thing as that double "for" loop, vectorized by doing:
img1 = uint8(255 * img1>127);
Of course thresholding gets far more complicated for the lower bits because you won't have just one range like here, you'll have 2, 4, ... 128 ranges depending on what bit you want to visualize. That's why I recommended bitget() instead of thresholding or dividing.
Categories
Find more on Display and Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!