Centerline Detection in an Image

조회 수: 7 (최근 30일)
Mitchell
Mitchell 2013년 10월 14일
댓글: Mitchell 2013년 10월 15일
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,

채택된 답변

Vivek Selvam
Vivek Selvam 2013년 10월 14일
편집: Vivek Selvam 2013년 10월 14일
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
Image Analyst
Image Analyst 2013년 10월 15일
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 2013년 10월 15일
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.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 10월 14일
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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by