Code bug with image algorithm

조회 수: 7 (최근 30일)
mona
mona 2014년 1월 16일
댓글: Walter Roberson 2014년 1월 17일
Hello there,
Here's a part of the code that I'm using to approximate an image and I'm kind of not understanding the problem with the last line. I'm suspecting there's something wrong with the datatype of m. The value of m is (sqrt(M)-1)/2 where M is the number of coefficients.
sizeImage = size(riceImage,1);
A = zeros(sizeImage);
sel = (sizeImage/2-m:sizeImage/2+sizeImage)+1;
A(sel,sel) = B(sel,sel);
  댓글 수: 1
José-Luis
José-Luis 2014년 1월 16일
It would be helpful if you posted the error you get.

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

답변 (1개)

Image Analyst
Image Analyst 2014년 1월 16일
Try this:
sizeImage = size(riceImage, 1); % Number of rows only (not # columns)
A = zeros(sizeImage); % rows by rows square image.
halfWidth = int32(sizeImage/2); % Round to nearest integer.
% The remaining code will go out of bounds and is nonsense.
% At least I don't understand the intent of it.
sel = (halfWidth -m : halfWidth + sizeImage)+1; % Maybe try end instead of sizeImage
A(sel,sel) = B(sel,sel); % No idea what this is supposed to do.
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 1월 17일
sizeImage/2+sizeImage is going to be greater than sizeImage so you are attempting to index outside the "A" that you defined.

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

Community Treasure Hunt

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

Start Hunting!

Translated by