hello, Can someone help me please I need to calculate number of pixel in each angle of a circle arround image like this
MATLAB: How can I calculate number of pixel in each angle of a circle?
circlepolar histogram
Related Solutions
A=imread('31.jpg');figure(1);imshow(A);
[gc1 gc2]=COG(A); % calculating center of gravity
gc1=round(gc1);gc2=round(gc2); hold all;figure(1);plot(gc2,gc1,'*r');A(find(A>125))=255; A(find(A<=125))=0; % simplify pixels range to binary
A(:,:,2)=and(A(:,:,2),A(:,:,3));A(:,:,3)=[];A=and(A(:,:,1),A(:,:,2));B=logical(~A); figure(2);imshow(B)figure(2);hold all;plot(gc2,gc1,'*r');% all the points of the CSI % attempts to avoid outer circle including all pixels of CSI
% [i1,j1]=ind2sub(size(B),find(B==1))
% intersect(find(B==1),sub2ind(size(B),xc2,yc2))
t=[0:1:360];r=20;xc=r.*cosd(t);yc=r.*sind(t);xc=xc+gc2;yc=yc+gc1;xc2=int64(floor(xc));yc2=int64(floor(yc));% figure(2);hc=plot(xc2,yc2,'r','LineWidth',1.5); % the initial circle
L2=[]; for k=1:1:length(xc2) L2=[L2; B(xc2(k),yc2(k))]; end while sum(L2)>0 % while sum(B(sub2ind(size(B),xc2(1:end),yc2(1:end))))>0
r=r+1; xc=r.*cosd(t);yc=r.*sind(t); xc=xc+gc2;yc=yc+gc1; xc2=int64(floor(xc));yc2=int64(floor(yc)); L2=[]; for k=1:1:length(xc2) L2=[L2; B(int64(round(xc2(k))),int64(round(yc2(k))))]; end % figure(2);hc=plot(xc2,yc2,'r','LineWidth',1.5);
endfigure(2);hc=plot(xc2,yc2,'r','LineWidth',1.5);
B(sub2ind(size(B),xc2(1:end),yc2(1:end))) % the values of the image on the circle points B(hc.YData,hc.XData)
prompt1={'key in degrees sector: '}; % input degrees per sector
dlg_title='sector degrees ';n_lines=1;default={'30'};sctr=inputdlg(prompt1,dlg_title,n_lines,default);sector_angle= str2num(cell2mat(sctr));p_center=[gc2 gc1];k=[0:sector_angle:360]; % split 360 angle into equal sector angles
rc1=r*exp(j*pi*k./180); x_arc1=real(rc1)+p_center(1); y_arc1=imag(rc1)+p_center(2); % get points sectors around outer PPI circle
hold all;figure(2);plot(x_arc1,y_arc1,'go');sector_scan=[p_center(1) x_arc1(1) x_arc1(2) p_center(1);p_center(2) y_arc1(1) y_arc1(2) p_center(2)];figure(2);plot(sector_scan(1,:),sector_scan(2,:),'b','LineWidth',1.5);
D=double(B);[yq,xq]=find(D);figure(2);plot(xq,yq,'*r'); % initiial test, just to visualise inpolygon input points are correct
[in,on]=inpolygon(xq,yq,sector_scan(1,:)',sector_scan(2,:)'); figure(2);plot(xq(in),yq(in),'*g')figure(2);plot(xq(on),yq(on),'*y')count=zeros(1,length(k)-1);for s=1:1:length(k)-1 sector_scan=[p_center(1) x_arc1(s) x_arc1(s+1) p_center(1);p_center(2) y_arc1(s) y_arc1(s+1) p_center(2)]; [in,on]=inpolygon(xq,yq,sector_scan(1,:)',sector_scan(2,:)'); count(s)=numel(xq(in))endcount'busiest_sector_count=max(count)emptiest_sector_count=min(count)figure(3);bar(count);grid on
If you find this answer of any help solving your question,
please mark it as ACCEPTED ANSWER.
To any other reader, if you find my answer of any help, please click on the thumbs-up vote link,
thanks in advance
John
If you just want the equivalent circular diameter, you can ask regionprops().
props = regionprops(mask, 'EquivDiameter');ECD = props.EquivDiameter; % Equivalent Circular Diameter - diameter of a circle with the same number of pixels as your blob.
If you want radius as a function of angle, then that's more complicated and involves using regionprops to find the centroid, bwboundaries() to find the outline, atan2d() to find the angle, and sqrt() to find the distance (radius) at that angle.
Best Answer