How to slice an image
Mostra commenti meno recenti
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));
Risposte (2)
Walter Roberson
il 26 Gen 2011
0 voti
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
il 27 Gen 2011
0 voti
Categorie
Scopri di più su Image Processing Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!