Clear Filters
Clear Filters

How can I crop image 1.jpg from 2.jpg in matlab(if it doesn't have boundary)?

2 views (last 30 days)
How can I crop image 1.jpg from 2.jpg in matlab? Is there any function? 1.jpg is a binary image and it hasn't a boundary and noice. I use blue color for white color here to understandable.
1.jpg
2.jpg

Accepted Answer

Image Analyst
Image Analyst on 1 Jun 2014
Here are the steps (one way at least - there are several ways to do it).
  1. convert to gray with rgb2gray()
  2. threshold binaryImage = grayImage < 128
  3. call bwconvhull
  4. call bwlabel to get labeledImage
  5. call regionprops(labeledImage..... and ask for 'BoundingBox'.
  6. expand bounding box coordinates by whatever amount you want.
  7. call imcrop(originalImage, boundingBox)
That pretty much does it, except for some things like imshow() to display your progress. See if you can do it all by yourself from this point on. Let me know how it goes.
  2 Comments
Indunie Florence
Indunie Florence on 1 Jun 2014
Edited: Indunie Florence on 1 Jun 2014
[Ilabel num] = bwlabel(Ifinal1);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Icrop = imcrop(I,Ibox);
I used this code segment and it doesn't work.
I can't set the boundary mannually because I don't know where the objects are in the image.
Indunie Florence
Indunie Florence on 1 Jun 2014
As you said, bwconvhull method solve the problem.. thank you thank you very much...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!