resizing an image not working.

12 ビュー (過去 30 日間)
Yaps
Yaps 2018 年 10 月 21 日
コメント済み: Yaps 2018 年 10 月 21 日

Hello, I am trying to resize a color image by using alternate pixel values. What I am getting is a blue image with a few black dots.I changed it to gray but now I am getting a white image with black image with a few black dots. Can someone tell me how to do the color resize, what is wrong with my script please

Thank you

    %read image
a =imread('beach.jpg');
a= rgb2gray(a);
[rows,columns] = size(a);
i = 1, j =1;
c=zeros(rows/2,columns/2);
for x = 1:2:rows
  for y = 1:2:columns
    c(i,j) = a(x,y);
     j = j + 1;
  end
  i = i +1;
  j = 1;
end
imshow(c);
  2 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 21 日
編集済み: madhan ravi 2018 年 10 月 21 日
upload your .jpg file to test , you didn't attach the file
Image Analyst
Image Analyst 2018 年 10 月 21 日

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

採用された回答

Guillaume
Guillaume 2018 年 10 月 21 日
編集済み: Guillaume 2018 年 10 月 21 日
For a greyscale image, your code is correct (as long as the size of the image is even) although note that iterating over rows in the inner loop and columns in the outer one would be faster due to the way matlab stores matrices in memory.
For colour image, your code will only look at the red channel, since it works on 2D arrays whereas colour images are 3D.
Of course, the whole thing is a waste of time, the following one liner would do the same more simply:
resizedimage = originalimage(1:2:end, 1:2:end, :);
with the added bonus that it works both for colour and greyscale images and works for odd and even sized images.
  1 件のコメント
Yaps
Yaps 2018 年 10 月 21 日
Thank you for your help. It is helping me to understand how matlab works.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by