Why I cant use the same for loop to interpolate the colomn? Only in row.
조회 수: 2 (최근 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!