There are three different ways this can be achieved. The three examples are shown below:
I = imread('peppers.png');
image(I); axis off;
disp('please selct the Region Of Interest')
ROI = roipoly(I);
myImage = findall(gcf,'type','image');
set(myImage,'AlphaData',ROI);
Method 2
I= imread('peppers.png');
image(I); axis off;
disp('please selct the Region Of Interest')
ROI = double(roipoly);
ROI = uint8(ROI);
figure
I2 = zeros(size(I));
I2(:,:,1) = ROI.*I(:,:,1);
I2(:,:,2) = ROI.*I(:,:,2);
I2(:,:,3) = ROI.*I(:,:,3);
image(uint8(I2)); axis off;
I= imread('peppers.png');
imshow(I);
rect = [290 160 220 165];
I2= imcrop(I,rect);
figure
imshow(I2);
Best Answer