Centerline Detection in an Image

16 visualizaciones (últimos 30 días)
Mitchell
Mitchell el 14 de Oct. de 2013
Comentada: Mitchell el 15 de Oct. de 2013
Hello,
I have a picture of a white tube against a black backdrop and I need to find a curve that follows the centerline of the tube. Not necessarily an equation for the curve just a graphical representation in a line graph or something. I am very very new to Matlab so I am not sure how to go about doing this.
What I have done so far is make the image in gray scale and then extracted the matrix. What I think I have to do now is find the maximum value in each row of the matrix since the white will have a higher value in the matrix. I cannot figure out how to do this though.
Another way I figured I could accomplish this is by doing a polyfit for each individual row since the values where the tube are appear to follow a quadratic relationship between the edges of the tube and the center. I could then find the maximum of each of of these polynomials and plot that. Again I don't know how to do this and the documentation doesn't help me.
So my main question is how do I find the column location of the maximum value of each row? So I get an output like:
Row | Column
1 12
2 13
3 14
4 13
5 12
6 11
7 10
or:
x=(1:7), y= 12 13 14 13 12 11 10
except obviously there are around 1000 entries for x
Thanks a lot,

Respuesta aceptada

Vivek Selvam
Vivek Selvam el 14 de Oct. de 2013
Editada: Vivek Selvam el 14 de Oct. de 2013
With your idea, this should get you started:
h = imread('0001cropped.jpg'); % read image as 3d matrix : H x W x D where D is 3 for RGB
figure(1); subplot(1,2,1); imshow(h) % on the left, plot the image
sumH = sum(h,3); % sum the RGB values of each pixel
maxRsumH = max(sumH,[],2); % find the maximum for each row
ima = zeros(size(maxRsumH)); % create a matrix of size H x W initialized to 0
for i = 1:length(sumH)
ima(i,sumH(i,:) == maxRsumH(i)) = 1; % wherever the maximum occurs change the value to 1
end
figure(1); subplot(1,2,2); spy(ima) % on the right, plot the points (values of 1)
  5 comentarios
Image Analyst
Image Analyst el 15 de Oct. de 2013
I'm sorry I didn't make myself clear enough. The Savitzky Golay filter should be run on your vector of centerline locations not on your image . You should not just apply my example to your whole image - that was just the example I used it for. See how I took a single line of pixel values from a row or column of the image and used sgolay()? Well pretend those values were centerline locations instead of gray levels. So you just pass in your centerline locations instead of pixel values. And of course you just have to do it once because you have just one vector - you don't need to do it for every line and every column in the image like I did, because you're not processing the image, you're processing a list of centerline locations. Does that make sense now?
Mitchell
Mitchell el 15 de Oct. de 2013
Oh yes I see this now, thanks a lot for your help. Now I just have to figure out how to repeat all this for 2000 images.
Thanks again.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 14 de Oct. de 2013
Something like this (untested)
[rows, columns, numberOfColorChannels] = size(yourImage);
for row = 1 : rows
thisRow = yourImage(row, :, 2); % Kth row from green channel
[maxValue, indexOfMax(row)] = max(thisRow);
end

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by