How to slice an image
10 次查看(过去 30 天)
显示 更早的评论
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));
0 个评论
回答(2 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!