??? Index exceeds matrix dimensions.

조회 수: 1 (최근 30일)
Gaurav
Gaurav 2014년 1월 27일
댓글: Amit 2014년 1월 27일
displayDetectedBlocks('2.jpg',1,1,2) ??? Index exceeds matrix dimensions.
Error in ==> displayDetectedBlocks at 3 pos = pairsVec(booleanDistance==1,1:2);
CODE
function Jt = displayDetectedBlocks(It,blocks,booleanDistance,pairsVec)
pos = pairsVec(booleanDistance==1,1:2);
[m,n] = size(blocks);
[blockSize(1),blockSize(2)] = size(blocks{1,1}.intensity);
Jt = It;
for i=1:size(pos,1)
[K,L] = ind2sub([m,n],pos(i,1));
topLeftPel = blocks{K,L}.topLeftPixel;
Jt(topLeftPel(1):topLeftPel(1)+blockSize(1)-1,topLeftPel(2):topLeftPel(2)+blockSize(2)-1) = ones(blockSize(1),blockSize(2));
end
figure
subplot(121),imshow(It),xlabel('Tampered Image'),
subplot(122),imshow(Jt),xlabel('Potential Tampered Image')

답변 (1개)

Amit
Amit 2014년 1월 27일
The error is in line
pos = pairsVec(booleanDistance==1,1:2);
You entered displayDetectedBlocks('2.jpg',1,1,2) and the pairsVec is a scalar or 1X1 matrix. In the line where the error appars, you're trying to access pairsVec's 2nd column which does not exist. That why the error appears.
  댓글 수: 2
Gaurav
Gaurav 2014년 1월 27일
Dear Amit
Can you suggest some inputs for displayDetectedBlocks('2.jpg',1,1,2)
CODE
function Jt = displayDetectedBlocks(It,blocks,booleanDistance,pairsVec)
pos = pairsVec(booleanDistance==1,1:2);
[m,n] = size(blocks);
[blockSize(1),blockSize(2)] = size(blocks{1,1}.intensity);
Jt = It;
for i=1:size(pos,1)
[K,L] = ind2sub([m,n],pos(i,1));
topLeftPel = blocks{K,L}.topLeftPixel;
Jt(topLeftPel(1):topLeftPel(1)+blockSize(1)-1,topLeftPel(2):topLeftPel(2)+blockSize(2)-1) = ones(blockSize(1),blockSize(2));
end
figure
subplot(121),imshow(It),xlabel('Tampered Image'),
subplot(122),imshow(Jt),xlabel('Potential Tampered Image')
Amit
Amit 2014년 1월 27일
You can input pairVec as something like [2 2] That will atleast correct the current error.
However, if you input booleanDistance anything other than 1, it will throw an error again.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by