# Do not plot the shape in the middle and polar transformation

조회 수: 1(최근 30일)
Alex Perrakis 2021년 11월 18일
댓글: Alex Perrakis 2021년 11월 18일
Hello Guys, i have the above seen plot and i would like not to plot the shape seen within the circle and the do a polar tranformation. So that that circle appears to be a line.
##### 댓글 수: 6표시숨기기 이전 댓글 수: 5
Alex Perrakis 2021년 11월 18일
and here is the 50

댓글을 달려면 로그인하십시오.

### 채택된 답변

편집: Adam Danz 2021년 11월 18일
This demo uses a cleaned up version of your code and then does the following,
1. Computes center of noisy circle
2. Shifts noisy circle to (0,0)
3. Converts shifted image to polar coordinates
4. finds the spike in rho values (radii) based on thresholding
5. Removes the spike.
If you want a smooth circle, you could fit the final (x,y) values to a cirlce (see example) or just use the median rho values in polar coordinates.
newpicture=imsubtract(pic01,pic050);
%imshow(newpicture)
% level = graythresh(newpicture);
level = 0.1405;
newbinpic = imbinarize(newpicture,level);
%imshowpair(newpicture,newbinpic,'montage')
newbinpic2=bwpropfilt(newbinpic,'perimeter',1);
% imshowpair(newbinpic2,newpicture,'montage');
boundaries = bwboundaries(newbinpic2,'noholes');
% Plot raw (x,y) values
x = boundaries{1}(:,2);
y = boundaries{1}(:,1);
figure()
subplot(2,2,1)
plot(x,y, 'r-')
title('raw values')
axis equal tight
hold on
% Assuming (x,y) is a noisy circle, find center
cnt = [min(x)+range(x)/2, min(y)+range(y)/2];
xline(cnt(1))
yline(cnt(2))
% Shift to (0,0) and compute polar coordinates
[theta, rho] = cart2pol(x-cnt(1), y-cnt(2));
% Plot in polar coord
subplot(2,2,2)
polarplot(theta, rho)
title('Polar coord.')
% Define a reasonable threshold to isolate the spike in RHO values
% 90% of the median looks OK
subplot(2,2,3)
plot(rho)
threshold = median(rho)*.9;
yline(threshold, '-k', 'Threshold')
ylabel('rho'); xlabel('index')
title('rho values')
% Find start and end of peak
peakIdx = find(rho < threshold);
peakIdx(2:end-1) = [];
xline(peakIdx(1)) % plot start of peak
xline(peakIdx(2)) % plot end of peak
% Remove the peak
theta(peakIdx(1):peakIdx(2)) = []; % you can do the same with x
rho(peakIdx(1):peakIdx(2)) = []; % you can do the same with y
% Plot the circle without the interior object
subplot(2,2,4)
polarplot(theta,rho)
title('Inner removed')
##### 댓글 수: 4표시숨기기 이전 댓글 수: 3
Alex Perrakis 2021년 11월 18일
thanks bro you did me a solid.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Polar Plots in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by