Ole
the following script answers your question, attached script and the image of your question with name used in the script.
Following, the script commented:
clc,cla;
format long;
A=imread('shaffen dass.jpg');
[sz1 sz2 sz3]=size(A);
szx=sz2;szy=sz1;
A1=A(:,:,1);A2=A(:,:,2);A3=A(:,:,3);
figure(1);imshow(A);
hold all;
Cx=floor(szx/2);Cy=floor(szy/2);
plot(Cx,Cy,'co');
Rmin=80;Rmax=400;
[centers, radii]=imfindcircles(A,[Rmin Rmax],...
'ObjectPolarity','dark','Sensitivity',0.9);
h=viscircles(centers,radii);
hold all;
[centers2, radii2]=imfindcircles(A,[Rmin Rmax],...
'ObjectPolarity','bright');
h=viscircles(centers2,radii2);
L=floor(2*pi*radii);
cx=floor(.5*(centers(1)+centers2(1)));
cy=floor(.5*(centers(2)+centers2(2)));
plot(cx,cy,'r*');
plot([cx 1],[cy 1],'r-.');
Observe image centre and inner circle centre are not aligned.
IF you try to sweep with a for loop using angle the chances are that depending upon how big is the image there are going to be missing pixels, or if step too big (image too small) either way it may deform resulting figure.
I also tried sweep following outer rectangular perimeter, it was getting complicated.
I choose to sweep with an outer circle 5 pixels away from the outer circle.
t=[45:360/L:404+1-360/L];
R=radii+5;x=R*sind(t)+cx;y=R*cosd(t)+cy;
hL1=plot(x,y,'m');
x_ref=hL1.XData;y_ref=hL1.YData;
Sx={};Sy={};
for k=1:1:numel(hL1.XData)
Lx=floor(linspace(x_ref(k),cx,ceil(R)));
Ly=floor(linspace(y_ref(k),cy,ceil(R)));
Sx=[Sx Lx'];Sy=[Sy Ly'];
end
Now Sx and Sy contain the indices to be used to point at the values of the start image.
sx=cell2mat(Sx);sy=cell2mat(Sy);
[s1 s2]=size(sx);
Out of answering other similar questions, building Red Green Blue and then assembling them is the simplest and fastest way:
B1=uint8(zeros(s1,s2));
B2=uint8(zeros(s1,s2));
B3=uint8(zeros(s1,s2));
for n=1:1:s2
for k=1:1:s1
B1(k,n)=A1(sx(k,n),sy(k,n));
B2(k,n)=A2(sx(k,n),sy(k,n));
B3(k,n)=A3(sx(k,n),sy(k,n));
end
end
C=uint8(zeros(s1,s2,3));
C(:,:,1)=B1;
C(:,:,2)=B2;
C(:,:,3)=B3;
figure(2);imshow(C);
Ole
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG