How to generate polar shape matrix of binary image?

3 次查看(过去 30 天)
Hello friends,
I want to know how to generate a polar shape matrix from an binary object. I have done my implement up to drawing polar diagram but I don't get idea how to generate shape matrix. My code is:
if true
% code
J=im2double(imread('images\sample1.jpg'));
K=rgb2gray(J);
I=im2bw(K);
radius_min=0;
radius_max=100;
angle=360;
make_square=0;
clc;
close all;
% Check the argument data
if (nargin < 1)
error('Error in the number of arguments (it should be >0). Use: I,radius_min,radius_max,angle,make_square');
end
% Check if there are some arguments by default
if exist('radius_min','var') == 0
radius_min = 0;
end
if exist('radius_max','var') == 0
radius_max = 100;
end
if exist('angle','var') == 0
angle = 60;
end
if exist('make_square','var') == 0
make_square=0;
end
% Check if the input argument data are valid
if (radius_min < 0)
error('radius_min sholud be >=0')
end
if (radius_max <= radius_min)
error('radius_max sholud be >radius_min')
end
if (angle<0 && angle>360)
error('angle sholud be 0<=angle<=360')
end
if (make_square ~= 0 && make_square ~= 1)
error('make_square sholud be either 0, or, 1')
end
% Plot the input image (rectangular coordinates)
figure(1)
%I=imadjust(I); %activate if needed
imshow((I));
title('Input image (rectangular coordinates)')
[M N]=size(I);
% If the option make_square==1, the input image is resized
if make_square==1
if(M>N) dim=M;
else dim=N;
end
I=imresize(I,[dim dim]);
[M N]=size(I);
end
% We rotate pi/2 the input image to have the desired view
I=imrotate(I,90);
% The mapping from cartesian to polar coordinates
theta_max=angle;
step_theta=theta_max/(N-1);
step_r=(radius_max-radius_min)/(M-1);
[r,theta] = meshgrid(radius_min:step_r:radius_max, -theta_max/2:step_theta:theta_max/2);
xx=-r.*cos(theta*pi/180)-radius_min;
yy=-r.*sin(theta*pi/180)-radius_min;
% Map the input image I to the polar coordinates xx,yy and represent as
% a surface surface (viewed from above)
figure(2);
H=surface(yy,xx,im2double(I),'edgecolor','interp');
colormap(gray)
view(0,90)
axis off
title('Output image mapped to polar coordinates')
% figure
% polar(theta,r);
point =[97.31;92.12]; %- the center point
nbins_theta =8; % - theta divide
nbins_r =5; %- r divide
h2 = axes('position',[0 0 1 1]);
gca;
hold on;
r_bin_edges=linspace(radius_min,radius_max,nbins_r);
% draw circles
th = 0 : pi / 50 : 2 * pi;
xunit = cos(th);
yunit = sin(th);
for i=1:length(r_bin_edges)
line(xunit * r_bin_edges(i) + point(1), yunit * r_bin_edges(i) + point(2),...
'LineStyle', ':', 'Color', 'k', 'LineWidth', 1);
end
% draw spokes
th = (1:nbins_theta) * 2*pi / nbins_theta;
cs = [cos(th);zeros(1,size(th,2))];
sn = [sin(th);zeros(1,size(th,2))];
line(radius_max*cs + point(1), radius_max*sn + point(2),'LineStyle', ':', ...
'Color', 'k', 'LineWidth', 1);
axis equal;
axis off;
hold off;
end
And the result is :
The further process is to generate polar shape matrix. The concept is If the circles intersect the maximum radius of the shape (line OA) at i1,i2,..., in-1, then starting from i1, i2, ..., in-1 and counter-clockwise, we divide each circle into m equal arcs, each arc being theta = 360/m degrees. Then an m x n matrix - which called shape matrix.
I would be thankful if someone helps me to implement this. Thanks in advance.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modify Image Colors 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by