The radii of my binary pattern in respect to its boundaries

1 view (last 30 days)
Hello,
I have this image:
with this code I convert it to the one below:
im=imread ('Original.bmp'); % Loading the image
im = im(20:770,70:820); % Defining a proper frame size, 751X751 will the size of the bim
h = fspecial('gaussian',101,15); % Filtering the image
bim = imfilter(im,h,'replicate'); % Filtering the image
bim = imbinarize(bim); % Convert the image in to binary
My bim image :
Cheifly I want to find the radii of the boundaries based on the center of the image (which is the small circle in the middle of the pattern.) for each degree. (counter clockwise) in a cell. In other words, in the end I will have a 360 by 1 matrix which is the values of each degree's rdius.
Besides, when I sketch the contour of the image with this code:
figure;
imcontour (bim,1,'r');
axis square;
Unfortunately, the boundaries are not smooth enough and when exporting it as a vector (so I can have it with the highest quality to use it in my text,); at some points, the lines are discontinuous:
contour_zigzag.bmp
I would be really appreciated if being suggested ways to tackle these obstacles.
Thanks a lot in advance.

Answers (1)

KSSV
KSSV on 17 Apr 2019
Edited: KSSV on 17 Apr 2019
I = imread('Image.bmp');
% Remove white background around corners
grayImage = min(I, [], 3);
binaryImage = grayImage < 200;
binaryImage = bwareafilt(binaryImage, 1);
[rows, columns] = find(binaryImage);
row1 = min(rows);
row2 = max(rows);
col1 = min(columns);
col2 = max(columns);
% Crop
I1 = I(row1:row2, col1:col2, :);
I2 = rgb2gray(I1) ;
idx = kmeans(double(I2(:)),2) ;
idx = reshape(idx,size(I2)) ;
% Pick the region required
[y,x] = find(idx==1) ; % it could be 1 or 2 check
plot(x,y,'.r')
idx = boundary(x,y) ;
plot(x(idx),y(idx))
iwant = [x(idx) y(idx)] ;

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!