image scrambling in matlab
1 view (last 30 days)
Show older comments
I have a frame of size 144*176 and i have generated pn sequence of same size. now i want to scramble image by using following method: For every bit value 1 in the PN sequence, the corresponding index in the image is exchanged with its diagonal counterpart using equation I(i,j)=p*I(j,i)+p′ * I (i, j) , Otherwise the image pixel is kept same. but there is
error:Attempted to access I(145,1); index out of bounds because size(I)=[144,176].
Error in project1 (line 21) I(i,j)=(s*I(j,i))+(s'*I(i,j)); but its working for image of size 256*256. whats going wrong here plz help me
here is its code: I=(mat2gray(originalImage)); figure; imshow(I); [m n]=size(I); seq1 = round(rand(size(I))); for i=1:m for j=1:n s= seq1(i,j) if s==1 I(i,j)=(s*I(j,i))+(s'*I(i,j)); end end end
0 Comments
Answers (1)
Image Analyst
on 11 Mar 2014
It's probably a color image. Don't do this:
[m n]=size(I);
Do this instead:
[m, n, numberOfColorChannels] = size(I)
EVER to an image you've just read in! I can't tell you how many times I've seen people with what appears to be a gray scale image but saved in jpg or bmp format as a 24 bit RGB image.
If numberOfColorChannels = 3 you have to decide what to do. Why would you have a color image instead of a gray scale image? Can you simply make it gray scale?
if numberOfColorChannels > 1
I = I(:,:,2);
end
3 Comments
Image Analyst
on 11 Mar 2014
Yes, because your code is still trying to access row 145 and there are only 144 rows. I don't know WHY it is, but the error message says that it is. You need to figure out why your loop is going past 144. Is it trying to go to 256, the original size of the matrix before you shrunk it?
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!