Why I cant use the same for loop to interpolate the colomn? Only in row.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Ameer Hamza
2018-5-29
编辑:Ameer Hamza
2018-5-29
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!