How to slice an image

조회 수: 10 (최근 30일)
Ouriz
Ouriz 2011년 1월 26일
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));

답변 (2개)

Walter Roberson
Walter Roberson 2011년 1월 26일
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 2011년 1월 27일
could u give me the example?

카테고리

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