How to xor the image pixel values with values in matrix form?
조회 수: 3 (최근 30일)
이전 댓글 표시
I am performing image encryption using diffusion method in that I have to xor the image pixel values with key matrix. The image and the matrix are of size 32*96. I am using color image. I have split the image into R,G,B planes. I have converted the pixel values of each plane into binary values using 'dec2bin' command as I need each binary value in 12 bits and also I have converted the decimal values in the matrix using the same command.
%Image of size 32*96 is read in FR
frr=dec2bin(FR(:,:,1),12); % for red plane
frg=dec2bin(FR(:,:,2),12); % for green plane
frb=dec2bin(FR(:,:,3),12); % for blue plane
q2=dec2bin(g,12); % g is the key matrix
q3=xor(frr,q2);% q2 is xored with red plane pixel value
When I did this I got 0 for all 12 bits in q3. When I tried 'xor(str2num(frr),str2num(q2))' I got the values in 1 bit either as 0 or 1 but I need the answer in 12 bits.
For eg, If frr(1,:)=1010000 and q2(1,:)=10101111 I need the answer as q3(1,:)=00001111 Please help me to resolve this issue. Thanks in advance.
댓글 수: 0
답변 (1개)
Jan
2018년 2월 20일
편집: Jan
2018년 2월 20일
You can XOR the values directly instead of converting them to char vectors at first.
frr = bin2dec('01010000');
q2 = bin2dec('10101111');
xor(frr, q2)
Or in your case
q3 = xor(FR(:, :, 1), g)
The indirection over converting the data to the char vector containing '0' and '1' is a waste of time. Note that dec2bin dos not create a binary variable, because Matlab does not have such a type yet.
댓글 수: 2
Jan
2018년 2월 21일
You do not want to get the decimal values, because you want a binary string to convert it to decimal values? The statement "the resultant image is in black and white" is not clear. It depends on how you display what, if it appears as a color or bw image.
The point of my answer is: Converting the data to binary strings is neither required nor efficient. It makes it harder to apply XOR. Better use XOR directly with the uint8 values - if you have them already. You did not explain, what your input FR is.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!