So ive been playing with the code following your suggestion, and I have it working ok. I can get it such that it will constantly play images, and will mark the center of my circle. Its a little slow (around 5.3 FPS), which isn't terrible for my purposes, but I will eventually be adding more computation per frame, so it would be nice to speed it up. I clocked it, and the majority of the time (almost 80%) is spent on the "regionprops", even though I limited it to only 3 properties. So my first question is, is there a quicker way to find objects in an image than regionprops?
My second issue is that the marker occasional jumps to other random points in the image from my circle. I was thinking of trying to limit the code so that it only searches for the circle in the same small region that it was in in the previous frame, and filter out circles whos area is widely different from the previous frame. Would this be the easiest way to do it? The only issue then would be if it picks the wrong point from the start, but hopefully that wont happen. The code I currently have is shown below. I can upload a sample frame too, but im not sure how to do it. Any help is appreciated. Thanks
thresholdvalue = 150; %Define threshold value binaryimage = grayimage > thresholdvalue; %Convert grayscale image to a binary image
info = regionprops(binaryimage,'Area','Perimeter','Centroid');
clear area perimeter centroid ratio %Clear needed variables
%Move regions from info to variables, and calc ratio closest = 100; %Closest finds the region with a radius (from area and perimeter) closest to 1. Start with a large value for i=1:length(info) if(info(i).Area >40 && info(i).Perimeter > 5) %eliminate regions with extremely small areas and perimeters ratio = abs(info(i).Perimeter^2/(4*pi*info(i).Area)) - 1; if(ratio < closest) closest = ratio; coords = info(i).Centroid; end end end
imshow(originalimage(:,:,:,1)); %Display image hold on; plot(coords(1),coords(2),'rx','MarkerSize',20) hold off; drawnow; end