Why I cant use the same for loop to interpolate the colomn? Only in row.
2 views (last 30 days)
Show older comments
Lena_half = imread('lena_half.tif');
Row = 512; % interp1 along row
[m,n,p] = size(Lena_half);
Enlarge_lena = zeros(m, Row, p);
xi = linspace(1, n, Row);
for i = 1:n
for j = 1:p
Enlarged = interp1(1:n,double(Lena_half(i,:,j)),xi);
Enlarge_lena(i,:,j) = Enlarged;
end
end
Enlarge_lena = uint8(Enlarge_lena);
figure(1)
imshow(Enlarge_lena)
Col = 512;
[a,b,c] = size(Enlarge_lena);
Enlarge_lenaCol = zeros(Col, b, c);
yi = linspace(1, a, Col);
for d = 1:a
for o = 1:c
Enlagred_le = interp1(1:a,double(Enlarge_lena(o,:,d)),yi);
Enlarge_lenaCol(o,:,d) = Enlarged_le;
end
end
Enlarge_lenaCol = uint8(Enlarge_lenaCol);
figure(2)
imshow(Enlarge_lenaCol)
I want to enlarge the whole image. Not only in one side, I want to make it 512*512.
0 Comments
Accepted Answer
Ameer Hamza
on 29 May 2018
Edited: Ameer Hamza
on 29 May 2018
You are making a mistake in indexing and length of for loops. Compare it with the following code to see the mistake. Also, there was a typo in two occurrences of Enlarged_le
Lena_half = imread('lena_half.tif');
Row = 512; % interp1 along row
[m,n,p] = size(Lena_half);
Enlarge_lena = zeros(m, Row, p);
xi = linspace(1, m, Row);
for i = 1:m % <---- You want to iterate on all rows, not columns
for j = 1:p
Enlarged = interp1(1:n,double(Lena_half(i,:,j)),xi);
Enlarge_lena(i,:,j) = Enlarged;
end
end
Enlarge_lena = uint8(Enlarge_lena);
figure(1)
imshow(Enlarge_lena)
Col = 512;
[a,b,c] = size(Enlarge_lena);
Enlarge_lenaCol = zeros(Col, b, c);
yi = linspace(1, a, Col);
for d = 1:b % <--- Iterate on all columns, not rows.
for o = 1:c
Enlarged_le = interp1(1:a,double(Enlarge_lena(:,d,o)),yi); % <-- indexing issue
Enlarge_lenaCol(:,d,o) = Enlarged_le; % <-- indexing issue
end
end
Enlarge_lenaCol = uint8(Enlarge_lenaCol);
figure(2)
imshow(Enlarge_lenaCol)
0 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!