how can xor first pixel with second and second with third and so on (for binary image)
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
image=imread('lena.jpg');
bin_image=dec2bin(image);
i have attached the pdf of my question kindly review
2 Comments
KALYAN ACHARJYA
on 1 Sep 2018
Edited: KALYAN ACHARJYA
on 1 Sep 2018
What do you mean by the second pixel...?
juveria fatima
on 1 Sep 2018
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
Accepted Answer
KALYAN ACHARJYA
on 1 Sep 2018
Edited: KALYAN ACHARJYA
on 1 Sep 2018
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
juveria fatima
on 1 Sep 2018
how can i get back the original image
juveria fatima
on 1 Sep 2018
thank you very much sir ,i got it
KALYAN ACHARJYA
on 1 Sep 2018
Edited: KALYAN ACHARJYA
on 1 Sep 2018
@Fatima My Pleasure
Recommended: Use vectorization to avoid loop
juveria fatima
on 4 Sep 2018
can i get back the rgb image
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));
juveria fatima
on 4 Sep 2018
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
KALYAN ACHARJYA
on 4 Sep 2018
@Fatima XOR for logical data (bit value) only 0 or 1, not for RGB and gray image
juveria fatima
on 4 Sep 2018
thank you, now am cleared with the doubts finally
Guillaume
on 4 Sep 2018
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.
juveria fatima
on 4 Sep 2018
@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?
juveria fatima
on 5 Sep 2018
Edited: juveria fatima
on 5 Sep 2018
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
juveria fatima
on 5 Sep 2018
Edited: Stephen23
on 5 Sep 2018
@Guillaume here is the link where i wrote the problem clearly
Abubakar Abba
on 1 Aug 2021
Why imshow(c);? I didnt see any variable c from the code. i think it should be imshow(new_image)
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Tags
See Also
on 1 Sep 2018
on 1 Aug 2021
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)