how can xor first pixel with second and second with third and so on (for binary image)

image=imread('lena.jpg');
bin_image=dec2bin(image);
i have attached the pdf of my question kindly review

2 Comments

What do you mean by the second pixel...?
kindly go through the pdf u will understand what i want to do bitxor(first column with second column) then bitxor(third with fourth)as follows for full image and then atlast i have to get back my original image

Sign in to comment.

 Accepted Answer

image=imread('image_name.image_format'); %e.g. im1.jpg
bw_image=im2bw(rgb2gray(image));
[row colm]=size(bw_image);
for i=1:row-1
for j=1:colm-1
new_image(i,j)=xor(bw_image(i,j),bw_image(i+1,j+1));
end
end
imshow(c);

15 Comments

@Fatima My Pleasure
Recommended: Use vectorization to avoid loop
can i get back the rgb image
Of course not, the first step binarises the image converting all colours to either black or white. Once the colour information has been removed there's no way to reinvent it.
You've accepted the answer so I assume that it does what you need but from the code in your question, it looks like what you call a binary image is not what we call a binary image (an image with only two colours) but the binary representation of a colour image (a step that is a complete waste of time if all you want to do is xor bits).
Note that the exact same result as the accepted answer can be achieved a lot faster (no loop) and with a lot less code with:
raw_image = imread('image_name.image_format'); %do not use image as a variable name, it's an often used matlab function
bw_image = im2bw(rgb2gray(raw_image));
new_image = xor(bw_image(1:end-1, 1:end-1), bw_image(2:end, 2:end));
oh thank you i was trying it
i have a doubt that instead of xor on binary image can we xor rgb image or gray image and process it
@Fatima XOR for logical data (bit value) only 0 or 1, not for RGB and gray image
thank you, now am cleared with the doubts finally
xor is a logical operator. The matching bit operator is bitxor. If you wanted to xor bits, then a) you shouldn't have accepted the answer as it doesn't do that at all and b) you need to clarify which bits you want to xor with which bits. I'm not sure whether you want to xor together bits of the same pixel or corresponding bits of neighbouring pixels.
@Guillaume i am sorry for silly mistakes actually am new to matlab , | | | I'm not sure whether you want to xor together bits of the same pixel or corresponding bits of neighbouring pixels.||| i actually want to xor the corresponding pixels value and at last i want to recover the image please go through the pdf file once i wrote my problem clearly
I'm afraid it's still not very clear what you want. Suppose you have a 4 column image. How many columns has the resulting image? Just 2 (first column is column 1 and 2 xor'ed, 2nd column is column 3 and 4 xor'ed)? How can you recover the original image from that?
Also are the rows xor'ed?
Giving us a concrete example would be a lot more useful than pdfs. E.g. given the image:
img = [208 33 162 72
231 233 25 140]
what is the desired result?
rgb_image_1 = imread('baboon.tiff');
q=dec2bin(rgb_image_1);
now to this image(q) i have to do bitxor pixel wise and recover the baboon image back
Why imshow(c);? I didnt see any variable c from the code. i think it should be imshow(new_image)

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!