![ https://i.stack.imgur.com/zaukG.jpg][1]

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.

1

There are 1 answers

0
AudioBubble On

% Load image from specified file

img1=imread('fractal.jpg');

% Display initial image

figure (1);
imshow(img1); 

% Scan through all rows in the image

for y = 1:size(img1, 1)

    % Scan col

    for x = 1:size(img1, 2)
        % img1 - MSB
        if img1(y,x) > 127

            % Turn one light pixel white

            img1(y,x) = 255;
        else

            % Turn one dark pixel black

            img1(y,x) = 0;
        end
    end

end

% Display image

figure (2);   
imshow(img1);