i have to do bitxor on image pixel wise

i have lena image as
rgb_image=imread('lena.png');
size of rgb_image is 512*512*3
rgb_image_1(1,1)
ans =
225
>> rgb_image_1(1,2)
ans =
224
bitxor(rgb_image_1(1,1),rgb_image_1(1,2))
ans =
1
first pixel value is 255 which bitxored with second pixel value 224 and the results is 1
similarly i will do for 3rd pixel and 4th pixel i.e
rgb_image_1(1,3)
ans =
224
>> rgb_image_1(1,4)
ans =
223
>> bitxor(rgb_image_1(1,3),rgb_image_1(1,4))
ans =
63
1) i have to do bitxor for complete image to form a new bitxored image
2) i have to get back the lena image by doing the reverse bitxor

1 Comment

You still need to clarify what the desired result is, as I asked in your other question.
Since you get one value by xor'in two pixels. Is the result half as big as the original?
As I said, give us an example of the desired output. E.g. for the matrix:
img = [208 33 162 72
231 233 25 140]
what is the exact desired output?
Side note: in matlab, the 2nd pixel, rgb_image(2), is rgb_image(2, 1), not rgb_image(1, 2).

Sign in to comment.

Answers (1)

From your latest comment, I'm unclear whether or not you've solved your problem. The code you've posted will always error when processing the last column and last row (since i+1 and j+1 go past the size of the image). In any case, a loop is not needed and the error-free, loop-free version of that code is:
rgb_image_1 = imread('lena.png');
new_image = bitxor(rgb_image_1(1:end-1, :, :), rgb_image_1(2:end, :, :));
recon_image = bitxor(rgb_image_1(:, 1:end-1, :), rgb_image_1(:, 2:end, :));
Note that necessarily, new_image will have one less column than the origignal image and recon_image one less row.

9 Comments

how do i get the complete column for new_image and complete rows for recon_image
  • Note that necessarily, new_image will have one less column than the origignal image and recon_image one less row.||
how do i get the complete column for new_image and complete rows for recon_image
I don't know. If you combine two columns to make just one column (the algorithm as you've described) then you always end up with one column less than you started with. If that's not what you want you need to come up with a different algorithm.
One option is to have one row and/or column be the same as the original. Would that be what you want?
That would certainly be useful if the process is to be reversed to restore the original image.
@ image Analyst yes exactly i want to reverse back to original image how to do it ?
Try this:
rgb_image_1 = imread('lena.jpg');
subplot(1, 2, 1);
imshow(rgb_image_1);
axis on;
title('Original Image', 'FontSize', 24);
new_image = bitxor(rgb_image_1(1:end-1, :, :), rgb_image_1(2:end, :, :));
recon_image = bitxor(rgb_image_1(:, 1:end-1, :), rgb_image_1(:, 2:end, :));
% Add on original left column (tack column 1 onto the left side):
recon_image_2 = rgb_image_1; % Initialize
recon_image_2(:, 2:end, :) = recon_image;
subplot(1, 2, 2);
imshow(recon_image_2);
axis on;
title('BitXOr Image', 'FontSize', 24);
how to get back the original lena image from bitxor lena image
Do the bitwise xor again and put the results to the right of a copy of the first column.
@juveria fatima, as this looks like homework you should put more effort in understanding with your encryption/decryption algorithm. You should have been able to work out yourself that you needed to keep around at least one column/row of the original image if you want to be able to reverse the encryption.
By necessity, a decryption algorithm can't use the original image for decrypting. Otherwise, there'd be no point in the encryption process in the first place. Now, look at the decryption code that you wrote. The problem should be obvious for yout to correct on your own.
You probably should think a bit more about what parts of the image you xor together. So far, you've been given code that does exactly what you ask. However, you'll notice that you calculate new_image and never do anything with it.

Sign in to comment.

Tags

Asked:

on 5 Sep 2018

Reopened:

on 10 Sep 2018

Community Treasure Hunt

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

Start Hunting!