Effacer les filtres
Effacer les filtres

image processing crop along boundaries

3 vues (au cours des 30 derniers jours)
Murstoe
Murstoe le 21 Avr 2020
Commenté : Image Analyst le 13 Mar 2021
Hi guys, I would like some tips to solve this problem. Thank for your help.
I have an image with some geometrical figures in it. I would like to obtain a new image with only the geometrical figures in it ( neglecting the backround). I also want to keep the intensity information of the starting image for the area inside the geometrical figures.
ps: i need to imbinarize the starting picture cause switching to gray image and thresholding the values doesn't work as desired.
I will attach my script.

Réponse acceptée

Image Analyst
Image Analyst le 21 Avr 2020
You forgot to attach tt so we can't see the image or the background. Please attach it. Is it being binarized properly?
You'll probably need to use "hold on" BEFORE you call plot so that you don't blow away the image.
And instead of axis square, you need to use
axis('on', 'image')
And I don't think the call to view() is needed.
Don't use image as the name of your variable since it's the name of a built-in function.
Finally you'll need to crop the image
originalImage = imread('tt');
hFig = figure
h1 = subplot(1, 3, 1);
imshow(originalImage);
BW = imbinarize(originalImage);
BW = bwareaopen(BW,500);
subplot(1, 3, 2);
imshow(BW)
% Make measurements.
props = regionprops(BW, 'BoundingBox');
B = bwboundaries(BW);
hold(h1, 'on');
for k=1:length(B)
% Display boundary in red over the original image.
boundary = B{k};
subplot(1, 3, 1);
plot(boundary(:,2), boundary(:,1), 'r-', 'LineWidth', 2);
axis('on', 'image');
% Display bounding box over image.
thisBB = props(k).BoundingBox;
rectangle('Position', thisBB, 'EdgeColor', 'y');
% Get a cropped image.
croppedImage = imcrop(originalImage, thisBB);
% Display the cropped image.
subplot(1, 3, 3);
imshow(croppedImage);
drawnow;
hFig.WindowState = 'maximized'
pause(0.7);
end
  1 commentaire
Murstoe
Murstoe le 21 Avr 2020
it works just fine! Thanks

Connectez-vous pour commenter.

Plus de réponses (1)

Aytaç Tok
Aytaç Tok le 12 Mar 2021
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
  3 commentaires
Aytaç Tok
Aytaç Tok le 13 Mar 2021
how can ı do that can u help me . can u share one example
Image Analyst
Image Analyst le 13 Mar 2021
Try this
  1. Click on the Apps tab ofthe tool ribbon
  2. Look in the Image Processing section for the Color Thresholder and click on it.
  3. Click the File Load menu and load your image from the file.
  4. Select a color space, such as HSV.
  5. Adjust the Value threshold to get just the banana.
  6. If it doesn't work well, then try to involve the Hue channel as we..
  7. Click the Export button to create a function for it.
  8. In your program, read in your image and then call the function that you exported.

Connectez-vous pour commenter.

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by