hi, I'm trying to solve an enlarge image problem. I need to enlarge image 1.7*x and 1.3*y But I'm getting error as

Attempted to access (0.7,0.3); index must be a positive
integer or logical.
Error in Untitled (line 5)
B((1.7*i-1),(1.3*j-1))=A(i,j);
Here is my code
A=double(imread('image'));
for i=1:256
for j=1:256
B((1.7*i-1),(1.3*j-1))=A(i,j);
B((1.7*i),(1.3*j-1))=A(i,j);
B((1.7*i-1),(1.3*j))=A(i,j);
B((1.7*i),(1.3*j))=A(i,j);
end
end
imshow(uint8(B));

 Accepted Answer

Halil - the error messages makes sense since the code is trying to access elements within the array B using non-integer indices. Why not use imresize to resize/scale your image given the required dimensions? Or are you trying to code this yourself? If the latter, you will probably have to do some sort of interpolation. See https://en.wikipedia.org/wiki/Image_scaling for some examples.

2 Comments

Yes, trying to code myself to improve my coding skills, thanks for helping.
Alright, sorry, I just thought you might want to know the easier, built-in way of doing it, that's why I gave the code below.
I see you accepted so you probably have it all working now, but if you still have problems, let us know. The only code you gave will have several problems - non-integer indices, and "holes" in the output image due to some pixels not being assigned. I guess you've realized that and fixed it.

Sign in to comment.

More Answers (1)

[rows, columns, numberOfColorChannel] = size(A);
newRows = 1.3 * rows;
newColumns = 1.7 * columns;
outputImage = imresize(A, [newRows, newColumns]);

Community Treasure Hunt

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

Start Hunting!