How to crop an image inside a boundary ?
Mostra commenti meno recenti
I have an image from which I want to crop a certain portion of it. I drew the boundary at first. Below is the code:
img = imread('Intensity1.jpg');
figure, imshow(img);
% getting a segment
h=drawfreehand();
position = wait(h);
region=uint8(roipoly(img,position(:,1),position(:,2)));
region=region.*img;
figure,imshow(region); title('Segmented Region');
% use bwperim rather than bwboundaries to get an Image of boundary.
boundImg = uint8(bwperim(rgb2gray(region),4));
boundImg(boundImg ~=0) = max(img(:));
figure, imshow(img + boundImg)
% save image without loosing information..
imwrite(img + boundImg, 'writeImg.jpg');
% check
read = imread('writeImg.jpg');
figure, imshow(read)
isequal(read, img + boundImg)
The image is below:

I want to crop the portion of the image specified by the boundary above. I tried the following line of code but there is no change in the result.
imcrop('Intensity1.jpg');
Any suggestions would be very much appreciated. Thank you.
3 Commenti
Kristen Meyer
il 19 Lug 2019
Modificato: Kristen Meyer
il 19 Lug 2019
So your image is read and you have a matrix discribing the selected area?
for i = 1:numCol
read(lowerRowIndexOfSelectionAtCol_i:end,i,:) = [];
read(1:upperRowIndexOfSelectionAtCol_i,i,:) = [];
end
Goes column by column and removes above and below selected area. Hopfully it's enough to get you where you need to go.
KALYAN ACHARJYA
il 20 Lug 2019
Modificato: KALYAN ACHARJYA
il 20 Lug 2019
@Warid Please do clarify your job to segment the yellowish region or extracts marked ROI only?
Warid Islam
il 22 Lug 2019
Risposta accettata
Più risposte (1)
Aytaç Tok
il 12 Mar 2021
0 voti
How can I get the object by auto cropping from a rgb picture. For example, there is a banana on the table and the background is black. I want to crop this picture and just take the banana and I want no background pixel at all. how can I do that
Categorie
Scopri di più su Contrast Adjustment in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!