image scrambling in matlab

조회 수: 3 (최근 30일)
Urmila
Urmila 2014년 3월 11일
댓글: Urmila 2014년 3월 12일
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

답변 (1개)

Image Analyst
Image Analyst 2014년 3월 11일
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
Image Analyst
Image Analyst 2014년 3월 11일
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?
Urmila
Urmila 2014년 3월 12일
sir i really don't understand whats going wrong in my loop.but my frame size is 144*176 and i dont want to resize it & want to scramble the pixels using above equation.can u plz suggest me any solution.Thank you.

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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by