whats wrong with this nearest neighbor zoom code

2 ビュー (過去 30 日間)
alireza kooshafar
alireza kooshafar 2016 年 10 月 22 日
コメント済み: Image Analyst 2016 年 10 月 23 日
I think every thing is ok but the answer is not correct
I=imread('C:\Users\AliReza\Desktop\B.jpg');
for Channel = 1 : 3
I1 = I(:,:,Channel);
S=2 ;
[M , N]=size(I1);
M2=S*M;
N2=S*N;
I2=zeros(M2 , N2);
for i =1:M2
for j = 1:N2
x =i/S;
y=j/S;
x2=round(x);
y2=round(y);
if (x2<1)||(x2>M)||(y2<1)||(y2>N)
I2(i , j)=0;
else
I2(i,j)=I1(x2 ,y2);
end
end
I3(:, :, Channel) = I2;
end
imshow(I3,[])
  1 件のコメント
John D'Errico
John D'Errico 2016 年 10 月 22 日
What do you think is incorrect? Why do you think there is a problem? Perhaps you need to either learn to use the debugger, or you need to give more information if you seriously expect an answer.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 23 日
Change
I2=zeros(M2 , N2);
to
I2 = zeros(M2 , N2, class(I));

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 10 月 22 日
Not sure what "is not correct" means. Perhaps you'd like to see the Mathworks demo on zooming an image, attached.
Or perhaps you want to use imresize() or imcrop().
  2 件のコメント
alireza kooshafar
alireza kooshafar 2016 年 10 月 23 日
dear image Analyst i write the code for gray and it works but when i want to do the same with rgb images just with adding channel i don't get the last result as i expected
Image Analyst
Image Analyst 2016 年 10 月 23 日
Looks like you've accepted Walter's answer so I assume you're all set now. Write back if that's not the case.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by