Help with getting data from image at equidistant positions from the centre – to include the “off circle corners”
Hello, I have an image and I want to get the median of data at each radius value. This is shown by the yellow circles – so each circle (take the median of all pixels on it).
However, in my attemy, I missing all the corners of data that are actually at a larger radius than the image size, but not full circles. Any suggestions how to include this data.
This was my attempt:
% 1st draw circle of radius R on the flog2 plot
theta = linspace(0,360); %use n=121 for every 3 degrees (reduce from every degree for speed
centre = [cx,cy]; %circle centre
% I= Image
[X,Y]=ndgrid(1:size(I,1),1:size(I,2));
X=X-cx;Y=Y-cy;%shift coordinate grid
hold(ax1,"on");
data=[];
for i=1:cy-1
radius=i; %circle radius
data(i,1)=i;
y = radius*sind(theta)+centre(2);
x = radius*cosd(theta)+centre(1);
%Get Data on radius
L=sqrt(X.^2+Y.^2)==radius;
data(i,2) = median(I(L));
if mod(i,5)==0
plot(ax1,x,y,’y’); %draw circle
end
% Now use interp so use all pixels on circle. This is
% actually what I finally use now
[xx,yy]=pol2cart(theta,radius); % this is for the interp2 approach
x=xx+cx; y=yy+cy;
vals=median(interp2(I,x,y));
data(i,3)=vals;
end
% Now plot data
hold(ax2,"on");
plot(ax2,data(:,1),data(:,3),’y-‘,’LineWidth’,3);Hello, I have an image and I want to get the median of data at each radius value. This is shown by the yellow circles – so each circle (take the median of all pixels on it).
However, in my attemy, I missing all the corners of data that are actually at a larger radius than the image size, but not full circles. Any suggestions how to include this data.
This was my attempt:
% 1st draw circle of radius R on the flog2 plot
theta = linspace(0,360); %use n=121 for every 3 degrees (reduce from every degree for speed
centre = [cx,cy]; %circle centre
% I= Image
[X,Y]=ndgrid(1:size(I,1),1:size(I,2));
X=X-cx;Y=Y-cy;%shift coordinate grid
hold(ax1,"on");
data=[];
for i=1:cy-1
radius=i; %circle radius
data(i,1)=i;
y = radius*sind(theta)+centre(2);
x = radius*cosd(theta)+centre(1);
%Get Data on radius
L=sqrt(X.^2+Y.^2)==radius;
data(i,2) = median(I(L));
if mod(i,5)==0
plot(ax1,x,y,’y’); %draw circle
end
% Now use interp so use all pixels on circle. This is
% actually what I finally use now
[xx,yy]=pol2cart(theta,radius); % this is for the interp2 approach
x=xx+cx; y=yy+cy;
vals=median(interp2(I,x,y));
data(i,3)=vals;
end
% Now plot data
hold(ax2,"on");
plot(ax2,data(:,1),data(:,3),’y-‘,’LineWidth’,3); Hello, I have an image and I want to get the median of data at each radius value. This is shown by the yellow circles – so each circle (take the median of all pixels on it).
However, in my attemy, I missing all the corners of data that are actually at a larger radius than the image size, but not full circles. Any suggestions how to include this data.
This was my attempt:
% 1st draw circle of radius R on the flog2 plot
theta = linspace(0,360); %use n=121 for every 3 degrees (reduce from every degree for speed
centre = [cx,cy]; %circle centre
% I= Image
[X,Y]=ndgrid(1:size(I,1),1:size(I,2));
X=X-cx;Y=Y-cy;%shift coordinate grid
hold(ax1,"on");
data=[];
for i=1:cy-1
radius=i; %circle radius
data(i,1)=i;
y = radius*sind(theta)+centre(2);
x = radius*cosd(theta)+centre(1);
%Get Data on radius
L=sqrt(X.^2+Y.^2)==radius;
data(i,2) = median(I(L));
if mod(i,5)==0
plot(ax1,x,y,’y’); %draw circle
end
% Now use interp so use all pixels on circle. This is
% actually what I finally use now
[xx,yy]=pol2cart(theta,radius); % this is for the interp2 approach
x=xx+cx; y=yy+cy;
vals=median(interp2(I,x,y));
data(i,3)=vals;
end
% Now plot data
hold(ax2,"on");
plot(ax2,data(:,1),data(:,3),’y-‘,’LineWidth’,3); image, ngrid, pol2cart MATLAB Answers — New Questions