-2

I have the image below and would like to measure the border irregularity of the image. That is, to specify if the border (edge) is regular or not.

enter image description here

I have been looking around, and found mostly research papers on the topic. Is there some function I can use in Python or MATLAB?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Simplicity
  • 47,404
  • 98
  • 256
  • 385

2 Answers2

2

As Yuval pointed out it really depends on what you call regular or irregular. But just for a quick start I take a naive assumption that regular means circle-like. Now to check if a body of pixels is circle-like I use regionprops function to calculate 'EquivDiameter' property:

Returns a scalar that specifies the diameter of a circle with the same area as the region. Computed as sqrt(4*Area/pi).

Then I use IOU measure to calculate irregularity. To test the code I used image from here.

The code is like this:

clc; close all; clear variables;
%% read image
I = imresize(rgb2gray(imread('maxresdefault.jpg')), 0.5);
I = imfill(medfilt2(I, [3 3])<230,'holes');
% I = imread('1.gif')>0; % load your GIF image
imshow(I); title('Shapes');

%% check irregularity
[L, n] = bwlabel(I);
S = regionprops('table', L, 'Centroid', 'EquivDiameter');
[X, Y] = meshgrid(1:size(I, 2), 1:size(I, 1));
r = zeros(1, n);
for i=1:n
   shape = L==i;
   circle = ((X-S.Centroid(i, 1)).^2+(Y-S.Centroid(i, 2)).^2)<(S.EquivDiameter(i)/2)^2;
   r(i) = 1-bwarea(shape&circle)/bwarea(shape|circle); % calculating ROI 
end

%% showing intersection
figure;
circs = im2double(repmat(I, 1, 1, 3));
circs = insertShape(circs, 'filledcircle', [S.Centroid S.EquivDiameter/2], 'LineWidth', 5);
imshow(circs); title('Intersections');

%% showing results
figure;
map = jet(256);
O = zeros(size(I), 'uint8');
for i=1:n
   ind = max(1,round(r(i)*256));
   O(L==i) = ind;
end
O = label2rgb(O, map);
O = insertText(O, S.Centroid, r, 'AnchorPoint', 'center', 'FontSize', 18);
imshow(O); title('Irregularity');
colormap jet;
colorbar('ticks', [0 1], 'TickLabels',{'Regular','Irregular'})

Results:

enter image description here enter image description here enter image description here enter image description here

saastn
  • 5,717
  • 8
  • 47
  • 78
0

Or just you can measure the circularity index using

        circularity_index=((4*np.pi*R.area)/pow(R.perimeter,2)) # circularity 
Jinen Daghrir
  • 63
  • 1
  • 8