# How do I compute coordinate of an image in Matlab?

63 views (last 30 days)
Alexander Killam on 10 Feb 2014
Edited: Thomas on 10 Feb 2014
I have an image. Lets say I call it bug...(It is an image of a small red bug with a white background). I want to be able to find the coordinates of where that bug is on matlab. I would like to be able to do this so that if I had another image in a different location I could track where the bug is in the new image. I am trying to learn matlab on my own so any in depth explanation would be greatly appreciated. Thank you very much!

Thomas on 10 Feb 2014
Edited: Thomas on 10 Feb 2014
It really depends upon what you want. If you only want to track a single point, or a few points within your image series this can be done very easily with the image processing toolbox function impixel:
The following script will let you open up a series of JPEG files, and allow you to interactively identify single or multiple points of interest in each image. The image coordinates are output to a cell matching the order of the input images, coords.
% Open all images using dialogue box
[FileName,PathName] = uigetfile('.JPG', 'select image files','multiselect', 'on');
images = transpose(FileName);
% open each image and interactively define the point of interest using impixel
% store output in a cell (coords)
coords = cell(size(images,1),1);
for i = 1:size(images)
[xi,yi,P] = impixel(im);
coords{i} = horzcat(xi,yi); % store xy coordinates from each point of interest
end
You may need to be more specific if you want something more sophisticated (i.e. to track all non white pixels.
Thomas
Thomas on 10 Feb 2014
Another route might be compute the barycentre of the non white pixels (i.e. identify each pixel where
im(:,:,1) < 255 || im(:,:,2) < 255 || im(:,:,3) < 255;
or set some other threshold and find their centre of mass). You would be including some of that fuzz around the bug into the calculation though.