|
westclox wrote:
>
>
> Im trying to write some code to detect objects in an image, I have
> come up with some psuedocode but I dont know how good this is,
> would
> like some advice on whether I could optimise it, also I dont know
> how
> to implement the repeat until loop i want in matlab, as well as not
> knowing how to find the m-connectivity of a pixel in the most
> efficient manner, at the step shown below, so would appreciate any
> help on how this can be done thanks
>
> Open image
> Get image size (Rows,Cols)
> Convert image to binary
>
> Objects = 1
> For M=1:Rows
> For N=1:Cols
> If (M,N)=1
> Objects = Objects + 1
> Record object start point (M,N)
>
> Repeat
> startpoint = M,N
> Check M-Connectivity
> If connected pixel found
> set startpoint = this pixel
> record this pixel into a matrix containing all points for this
> object
> Until no connectivity found
> %end of object
> end
> end
> end
Hello
If you have the Image Processing ToolBox it will make your life much
more simpler. It has all the builtin function to accomplish your
requirement.
ex:
I = imread('rgb.jpg');
gray = rgb2gray(I);
bw = im2bw(gray,graythresh(gray));
L = bwlabel(bw);
stats = regionprops(L,'All');
Play around the stats and you got all the binary object properties
you can think of.
HTH
Vihang
|