Image reduction issues/problems?
이전 댓글 표시
Hi. My program is coded so if the height or width of an image is larger than 400 pixels it reduces the width and height with a reduction factor 0.5. I have a menu that also asks the user to choose 'yes' or 'no' wether he want to make the image into a shape of a square (all sides have equal lengths). The problem is I can't figure out how to display and use the normal image after when the user pressed 'no'. The image is converted to black and white and then the user is asked to input a radius for a circular frame to be on top of the image.
im = imread('michelle_pf.jpeg');
reductionFactor = 0.5;
[h,w,kanaler] = size(im);
if h>400 || w > 400
im_r = imresize(im, reductionFactor);
end
m = menu('Do you want the image be in a shape of a square?','yes','no');
if m == 1
[h,w,kanaler] = size(im);
im_k = im(1:min(h,w),1:min(h,w),:);
im_g = rgb2gray(im_k);
im_d = im2double(im_g);
rgbImage = im_d;
elseif m==2
rbgImage = im_r;
end
[rows columns numberOfColorChannels] = size(rgbImage);
[columnsInImage rowsInImage] = meshgrid(1:columns, 1:rows);
centerX = columns/2;
centerY = rows/2;
radius = input('What should the radius of the circular frame be?');
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
maskedRgbImage = bsxfun(@times, rgbImage, cast(circlePixels, class(rgbImage)));
if radius <= min([rows columns]) / 2
figure(1),clf
imshow(im)
figure(2),clf
imshow(im_k)
figure(3),clf
imshow(im_d);
figure(4),clf
imshow(maskedRgbImage);
else
disp('NB! Radius have to be smaller or equal to the pictures dimensions');
k = menu('NB! Radius have to be smaller or equal to the pictures dimensions. Try again?','Yes,'No');
if k == 1
filename.m
elseif k== 2
return;
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!