How to do automatic image cropping?

1 次查看(过去 30 天)
Rob
Rob 2013-3-22
Hi there, The following image
contains two rectangles- one on the top of the other. They are on a black background, have close shades of light gray and have different orientations. The upper rectangle is always close to the left side of the image.
I managed to crop the desired polygon (with fixed vertex values). But I want to apply it for a set of images and the size of the two rectangles might vary from one image to other (the upper reclangle remains always close to the left side to the image). I want to be able to do the cropping automatically. Can you help please.
Thanks.
  4 个评论
Rob
Rob 2013-3-25
Thank you both for you comments and suggestions. I will try to ask these many questions.
>Can we count on the rectangles being different intensities? >They seem to be different on the right, but the right paper that extends >below the left paper seems to be the same intensity there. Both rectangles have slight difference in intensity. In the given image exemple, the top rectangle that I want to crop is very light gray and the one below is nearly white.
>Does its intensity change from place to place on the rectangle? indeed, the intensity can change from region to region on the rectangle.
>Do you know how many corners will be visible? Case1: 4 corners of top reclangle visible (top left, top right, bottom left, bottom right) + No corner from rectangle below Case2: 4 corners of top reclangle visible (top left, top right, bottom left, bottom right)+ 1 corner from rectangle below (bottom left) Case3: 3 corners of top reclangle visible (top left, top right, bottom left) + No corner from rectangle below Case4: 4 corners of top reclangle visible (top left, top right, bottom left)+ 1 corner from rectangle below (bottom left)
>Do you want to crop the bounding box of the union of the two rectangles, >or do you need the bounding box of each rectangle by itself? I need the bounding box of each rectangle by itself. In fact, What I get from following your demo steps is the all region containing both rectangles as one and don't seem to be able to separate them.
>Why are you doing this? What is the need, or use case? To extract one rectangle overlapping another.
>What do you need as the final output, in other words, do you need images >with tilted papers on it, or arrays of coordinates of the corners? The final result will be an image with the tilted upper rectangle.
>What is the next step in your processing once you have this output? This is the last process.
>Is there any way to avoid the papers overlapping in the first place? No.
Image Analyst
Image Analyst 2013-3-25
Please elaborate on this: ">Why are you doing this? What is the need, or use case? To extract one rectangle overlapping another." That is not a use case. That sounds just like some kind of homework assignment or project with no real world use, A real world use case would be something like you have a stack of white tiles that workers stacked out of the kilns and a robot with suction cup or parallel gripper fingers needs to orient its arm-mounted to pick up each tile and put each tile into a box at a fixed, known orientation. So why would any care that you have a bunch of images with the top paper segmented out? What good are they? Who is going to act or make decisions based on those images and what are those acts or decisions going to be?

请先登录,再进行评论。

回答(2 个)

Sean de Wolski
Sean de Wolski 2013-3-22
编辑:Sean de Wolski 2013-3-22
  1. Threshold ( graythresh() and im2bw())
  2. Get the boundingbox ( regionprops() )
  3. Extract it using simply indexing
  1 个评论
Rob
Rob 2013-3-25
Thanks for your suggestions. So far, top and bottom rectangles results in one region and cannot manage to separate them ...

请先登录,再进行评论。


Image Analyst
Image Analyst 2013-3-22
Thresholding is easy. And there is a corner() function to find corners. But if you want to get two rectangles out you'll need an algorithm for what to do if you have 4, 5, 6, 7, or 8 corners. Do you have that? That's no so straightforward. Plus what if they both overlap so that you have one long rectangle at, say, 1.7 times the area? You'll also need special code to handle that.
  2 个评论
Image Analyst
Image Analyst 2013-3-22
See my Image Segmentation Tutorial where I go over thresholding and cropping out objects: BlobsDemo
Rob
Rob 2013-3-25
Thanks for your suggestions. Corners function doesn't detect all corners.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by