I'm trying to perform the XOR operation between a 4x4 block of an image and a pseudo-random matrix of size 4x4.

조회 수: 5 (최근 30일)
pic = imread('Spiderman.png');
grey_pic = rgb2gray(pic);
imshow(grey_pic)
pseudo_randommat = randi(255,4,4);
fprintf('The Pseudo-Random Matrix generated:\n')
disp(pseudo_randommat)
pixel_values=grey_pic(186:189,165:168);
fprintf('Intensities of a 4x4 size pixel block from the original pic:\n')
disp(pixel_values)
fprintf('Performing XOR operation on the two blocks:\n')
decimal_tobinaryofPRS = dec2bin(pseudo_randommat);
decimal_tobinaryofPic = dec2bin(pixel_values);
performing_xor = xor(decimal_tobinaryofPRS,decimal_tobinaryofPic);
after_xor = bin2dec(performing_xor);
disp(after_xor)
I created a pseudo random matrix of size 4x4 and considered a 4x4 block of an image. I'm trying to perform XOR operation between them. So I tried to convert the intensity values of both matrices to binary and perform the XOR and convert it back to decimal and print the output. But my code doesn't seem to work. If you know the solution to this problem please share it with me. Thank you.

채택된 답변

DGM
DGM 2022년 7월 26일
편집: DGM 2022년 7월 26일
Use bitxor() on arrays of uint8 class. You'll have to cast your random array to match using uint8().
A = uint8([1 2 3])
A = 1×3
1 2 3
B = uint8([2 3 4])
B = 1×3
2 3 4
C = bitxor(A,B)
C = 1×3
3 1 7
  댓글 수: 3
DGM
DGM 2022년 7월 26일
Sorry about the incomplete answer. My network connection is barely usable at the moment, and I just posted what I could before I got disconnected.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by