image processing crop along boundaries

조회 수: 7 (최근 30일)
Murstoe
Murstoe 2020년 4월 21일
댓글: Image Analyst 2021년 3월 13일
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.

채택된 답변

Image Analyst
Image Analyst 2020년 4월 21일
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개)

Aytaç Tok
Aytaç Tok 2021년 3월 12일
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
Aytaç Tok
Aytaç Tok 2021년 3월 13일
how can ı do that can u help me . can u share one example
Image Analyst
Image Analyst 2021년 3월 13일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by