From: Amila Prabandhika on
Hi all,

I need some help in finding the location of an object in an image. I managed to convert the image from rgb2gray and then from gray to black and white. There after i removed the remaining unwanted objects by using bwareaopen function and then used the bwboundary function to find the boundary of the remaining objects in the image.

Therefore now i have managed to find the object I am focusing on in the image and the boundary drawn around the image.

Note: The object which is focused on has the largest boundary compared to others.

The next step which i need help is, to find the location of this particular object which i managed to get the boundary on.

The coding i have used so far is as follows :

I = imread('Test2.jpg');
Gray = rgb2gray(I);
darkobjectvalue = 60;
nodarkobject = imextendedmax(Gray, darkobjectvalue);
imshow(nodarkobject)
figure, imshow(nodarkobject);
sedisk = strel('disk',3);
noSmallStructures = imopen(nodarkobject, sedisk);
noSmallStructures = bwareaopen(noSmallStructures, 3000);

imshow(noSmallStructures);

[B,L,N] = bwboundaries(noSmallStructures);

hold on;
for k=1:length(B),
boundary = B{k};
if(k>N)
plot(boundary(:,2), boundary(:,1),'r','LineWidth',2)
end
end

The result for the above code is uploaded to the below link.
http://a.imageshack.us/img541/1170/test2result.jpg


Thank you for ur time and effort in advance,

Amila.
From: Ashish Uthama on
Amila,

Could you elaborate on what you mean by 'location'?

*You could obtain the centroid of the points along the boundary (mean)
*You can obtain the bounding box of the object (min/max)

Have a look at the REGIONPROPS function too. It can do both of this (and
more).
From: Amila Prabandhika on
Ashish Uthama <first.last(a)mathworks.com> wrote in message <i2jtb4$i8l$1(a)fred.mathworks.com>...
> Amila,
>
> Could you elaborate on what you mean by 'location'?
>
> *You could obtain the centroid of the points along the boundary (mean)
> *You can obtain the bounding box of the object (min/max)
>
> Have a look at the REGIONPROPS function too. It can do both of this (and
> more).


Hi Ashish,

Thanks for your reply! I will check the function out and let you know.

But what i meant by location is, the position of the pixel value of the boundary which is plotted on the image. The (x, y) co-ordinates of the pixels in that image involved in the boundary.

Once that is found out, i need to extract that part of the image out and further analyze it carry out some pattern matching.

Thanks for your help again.

Tc,

Amila.
From: Ashish Uthama on
> But what i meant by location is, the position of the pixel value of the
> boundary which is plotted on the image. The (x, y) co-ordinates of the
> pixels in that image involved in the boundary.

That is exactly what bwboundaries returns.



Maybe this helps:


RGB = imread('peppers.png');
BW = rgb2gray(RGB)>180;
imshow(BW); hold on;
[B,L,N,A] = bwboundaries(BW);

%arbitrarily pick the 60th 'object'
boundary = B{60};
%the x and y coodinates of this object are:
plot(boundary(:,2), boundary(:,1),'r');
hold off;

%extract the garlic using a 'boundin box' derived from the boundary
garlic = RGB( ...
min(boundary(:,1)):max(boundary(:,1)),... %the rows
min(boundary(:,2)):max(boundary(:,2)),... %the cols
:); %the RGB components

figure;imshow(garlic);
From: Amila Prabandhika on
Ashish Uthama <first.last(a)mathworks.com> wrote in message <i2k14r$ndg$1(a)fred.mathworks.com>...
> > But what i meant by location is, the position of the pixel value of the
> > boundary which is plotted on the image. The (x, y) co-ordinates of the
> > pixels in that image involved in the boundary.
>
> That is exactly what bwboundaries returns.
>
>
>
> Maybe this helps:
>
>
> RGB = imread('peppers.png');
> BW = rgb2gray(RGB)>180;
> imshow(BW); hold on;
> [B,L,N,A] = bwboundaries(BW);
>
> %arbitrarily pick the 60th 'object'
> boundary = B{60};
> %the x and y coodinates of this object are:
> plot(boundary(:,2), boundary(:,1),'r');
> hold off;
>
> %extract the garlic using a 'boundin box' derived from the boundary
> garlic = RGB( ...
> min(boundary(:,1)):max(boundary(:,1)),... %the rows
> min(boundary(:,2)):max(boundary(:,2)),... %the cols
> :); %the RGB components
>
> figure;imshow(garlic);

Hey Ashish,

Thanks alot for your help. I managed to get the pattern out of the image. But the only problem is, this code works only for the image i have provided. I tested with the other images that the system should be tested with, and it seems to be extracting something else! So i will have to read on this and try to make it work for all the images that the system should check for.

But thanx alot for ur effort.

tc,

Amila.