How to slice an image

10 views (last 30 days)
Ouriz
Ouriz on 26 Jan 2011
I have a binary image of number (0 1 2 3 4 5 6 7 8 9) and I want to slice that image into 10 image. So the number 0 become 1 image, number 1 become 1 image, and so on.
How to get the coordinate of start point and end point from each number?
I have tried make an algorithm like this:
mmY = [size(I, 1) 0]; mmX = [size(I, 2) 0]; for y = 1:size(I, 1) for x = 1:size(I, 2) if I(y, x) == 1 if x < mmX(1) mmX(1) = x; end for x = mmX(1):size(I, 2) if I(y, mmX(1)) == 1 if x > mmX(2) mmX(2) = x; end end end end end
O = I(:, mmX(1):mmX(1)+mmX(2));

Answers (2)

Walter Roberson
Walter Roberson on 26 Jan 2011
Tricks I learned from imageanalyst:
Threshold the image if there is any grey-level noise. imlabel() 8-connected objects in the image. regionprops() the labeled image and go through the stats and discard any small objects (i.e., noise.) Then for each remaining region, the BoundingBox value will tell you the minimum and maximum X and Y coordinates of the region. You can extract directly from the original image using those coordinates. If you are required to slice into rectangles, you could sort the lower and upper X bounds, discard the first lower and last upper, and then average each upper with its corresponding next lower to determine the X that would slice half-way between the objects.

Ouriz
Ouriz on 27 Jan 2011
could u give me the example?

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!