Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a nearly circular band of bright pixels in this image

This is the problem I have: I have an image as shown below. I want to detect the circular region which I have marked with a red line for display here (that particular bright ring).

enter image description here

Initially, this is what I do for now: (MATLAB)

binaryImage = imdilate(binaryImage,strel('disk',5)); 
binaryImage = imfill(binaryImage, 'holes'); % Fill holes.
binaryImage = bwareaopen(binaryImage, 20000); % Remove small blobs.
binaryImage = imerode(binaryImage,strel('disk',300));
out = binaryImage;
img_display = immultiply(binaryImage,rgb2gray(J1));
figure, imshow(img_display);

enter image description here

The output seems to be cut on one of the parts of the object (for a different image as input, not the one displayed above). I want an output in such a way that it is symmetric (its not always a perfect circle, when it is rotated).

I want to strictly avoid im2bw since as soon as I binarize, I lose a lot of information about the shape.

This is what I was thinking of:

I can detect the outer most circular (almost circular) contour of the image (shown in yellow). From this, I can find out the centroid and maybe find a circle which has a radius of 50% (to locate the region shown in red). But this won't be exactly symmetric since the object is slightly tilted. How can I tackle this issue?

I have attached another image where object is slightly tilted here

like image 682
Saania Avatar asked Jul 15 '15 14:07

Saania


1 Answers

I'd try messing around with the 'log' filter. The region you want is essentially low values of the 2nd order derivative (i.e. where the slope is decreasing), and you can detect these regions by using a log filter and finding negative values. Here's a very basic outline of what you can do, and then tweak it to your needs.

img = im2double(rgb2gray(imread('wheel.png')));
img = imresize(img, 0.25, 'bicubic');

filt_img = imfilter(img, fspecial('log',31,5));
bin_img = filt_img < 0;

subplot(2,2,1);
imshow(filt_img,[]);

% Get regionprops
rp = regionprops(bin_img,'EulerNumber','Eccentricity','Area','PixelIdxList','PixelList'); 
rp = rp([rp.EulerNumber] == 0 & [rp.Eccentricity] < 0.5 & [rp.Area] > 2000);

bin_img(:) = false;
bin_img(vertcat(rp.PixelIdxList)) = true;
subplot(2,2,2);
imshow(bin_img,[]);

bin_img(:) = false;
bin_img(rp(1).PixelIdxList) = true;
bin_img = imfill(bin_img,'holes');

img_new = img;
img_new(~bin_img) = 0;

subplot(2,2,3);
imshow(img_new,[]);

bin_img(:) = false;
bin_img(rp(2).PixelIdxList) = true;
bin_img = imfill(bin_img,'holes');

img_new = img;
img_new(~bin_img) = 0;

subplot(2,2,4);
imshow(img_new,[]);

Output:

enter image description here

like image 174
JustinBlaber Avatar answered Oct 05 '22 22:10

JustinBlaber