Centerline and bounding curve in image

7 visualizaciones (últimos 30 días)
Prabhat Srivastava
Prabhat Srivastava el 9 de En. de 2021
Comentada: Prabhat Srivastava el 9 de En. de 2021
I have an Image to which I want to fit a centerline and extract the bounding curves of the object. Here is the image and the best that I could manage with my code.
I = img(501:3500,501:5500);
im_bin = imbinarize(I);
se = strel('disk',3);
opened_im = imopen(im_bin,se);
BWdfill= imfill(opened_im, 4,'holes');
BWoutline= bwperim(BWdfill);
Segout = I;
Segout(BWoutline) = 255;
for indx = 1:5000
temp = find(BWoutline(:,indx)==1);
if isempty(temp)==1
temp= NaN;
else
end
top(indx) = max(temp);
bottom(indx) = min(temp);
end
top_temp = sgolayfilt(top,polsgf, winsgf);
top1 = fillmissing(top_temp,'movmedian',10);
bottom_temp = sgolayfilt(bottom, polsgf, winsgf);
bottom1 = fillmissing(bottom_temp,'movmedian',10);
[maxR, Idx1] = max(I,[],1);
const1 = mean(Idx1,"omitnan");
for k = 1:length(Idx1)
if Idx1(:,k) == 1
Idx1(:,k) = NaN;
else
end
end
Idx1 = fillmissing(Idx1,"constant",const1) ;
Cline = sgolayfilt(Idx1, polsgf, winsgf);
Ignore the white line in the output image that is a scale bar.

Respuesta aceptada

Roy Kadesh
Roy Kadesh el 9 de En. de 2021
If this complex code doesn't work, can't you try something easy?
img=imread('1.png');
I = img(501:3500,501:5500);
im_bin = imbinarize(I);
mmm=zeros(size(im_bin,2),3);
for col=1:size(im_bin,2)
ind=find(im_bin(:,col));
mmm(col,:)=[min(ind) mean(ind) max(ind)];
end
figure(1),clf(1)
imshow(I)
hold on
plot(mmm)
This works better and should be easier to fine-tune.
  1 comentario
Prabhat Srivastava
Prabhat Srivastava el 9 de En. de 2021
Editada: Prabhat Srivastava el 9 de En. de 2021
Thank you. I have tried this. I have a number of such images so algorithm fails in some images because they don't have consistent structure. The process that you have suggested is what I am trying too. This certainly is more elegant than mine. Thank you very much.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 9 de En. de 2021
You can either scan the image columns, or use bwskel. In the attached code I do it both ways.
If you want, you could smooth the rows.
  3 comentarios
Image Analyst
Image Analyst el 9 de En. de 2021
The advantage of the skeleton is that the center will be the center even if the blob is tilted (if that's what you want). The scanning method only looks in the vertical direction (1-D), not 2-D like the skeleton. These approaches could differ at times in where they find the centerline, with the skeleton being the more accurate way. Imagine if your blob had a shape like a C or an S instead of something horizontal. What would the column scanning way give you? Yeah, exactly -- now you get it. A line straight through the half way point vertically (actually even goes outside the blob itself), it will NOT be a centerline following the curve that is the blob. So, beware.
Prabhat Srivastava
Prabhat Srivastava el 9 de En. de 2021
I see!! Sure, I will experiment with these to see which one gisve the best estimation. Thank you.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by