필터 지우기
필터 지우기

Locating (x,y) position of an object

조회 수: 12 (최근 30일)
Alex Mason
Alex Mason 2011년 8월 16일
Hi guys
Been scratching my head over this one.
The premise is, I have series of images generated from a video file. The video in question is a video observing spark discharges.
Currently I build up an intensity style image, in grayscale, highlighting where the discharge has been.
1) Get the video frame as RGB uint8 image 2) Convert to grayscale 3) Make all values <254 0, leaving just 254,255 I.E. Pure white. 4) some other code that cumulatively adds the images to build up a map of where the spark has been*
What I want to do now is,locate the discharge in terms of pixel position. Now to avoid picking up random splodges of white left over from stage 3), MatLab is going to have to find a roughly verticle line of white. The discharge shows up as a bold column of white. Ill then need to find the central co-ords of that column then compare those coordinates to a set of pre-defined coordinate boundaries. (ie the image is divided into rectangular regions) so I can determine which region it was in and then count it.
Can I use the find command to do this? I think I have the image processing tool box on this machine as well. Any special commands in there?
Here is an example of the type of thing I am trying to find
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2011년 8월 16일
So the discharge is that series of blobs in the center left?
I think imclearborder and bwareaopen should take care of most of it.

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

답변 (3개)

Image Analyst
Image Analyst 2011년 8월 16일
Do a dilation followed by bwconncomp and regionprops to get the largest blob. (By the way, I just shared with the imaging team at the Mathworks the need to have a function to keep the n largest blobs, as well as the need to rename bwareaopen which has nothing at all to do with morphology or opening.) Anyway, then use that dilated image as a mask on your original image. Then you will have only the spark blobs (though broken up). If you want to join it together after that masking, then use a vertical structuring element because the lines cutting it are horizontal and a vertical structuring element will get rid of those only and not widen the blob. Let me know if you need code. It shouldn't be very hard at all. See my BlobsDemo if you need a tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862. If you need explanation of what a structuring element is, let me know (basically it says what elements to include or exclude in the operation).
  댓글 수: 2
Alex Mason
Alex Mason 2011년 8월 17일
Thanks for this Image Analyst
Ok so I think it does what I want. What I do is this... It might not be the most efficient but it seems to work!!!
So I convert to a binary image where 255 = 1, everything else = 0
I set up a structure, small rectangle.
I dilate the image
I use bwconncomp(Image, 8)
I then use that to get Total No of objects, I use the PixelIdxList to find the biggest bunch of pixels and their position in that objects matrix (idx).
I then do a for loop, from z = 1 to Total No of Objects where:
if z does not equal idx, then I make that particular objects pixels = 0
if z = idx, I leave it alone.
This removes, one by one all the small blobs and leaves me with just the big blob which hopefully will always be the spark. I can then use regionprops to get area, centroid and orientation.
FF = rgb2gray(FF);
FF = FF>=254;
FF = im2bw(FF);
imshow(FF);
SE = strel('rectangle',[20,5]);
FF2 = imdilate(FF, SE);
imshow(FF2)
CC = bwconncomp(FF2, 8)
TotalBlobs = CC.NumObjects
numPixels = cellfun(@numel,CC.PixelIdxList)
[biggest,idx] = max(numPixels) %gives me the biggest blob of pixels
%FF2(CC.PixelIdxList{8}) = 0;
for z = 1:TotalBlobs
if z ~= idx
FF2(CC.PixelIdxList{z}) = 0;
%imshow(FF2)
else
end
end
imshow(FF2)
CC = bwconncomp(FF2,8)
TotalBlobs = CC.NumObjects
S = regionprops(FF2,'Area','Centroid','Orientation')
Alex Mason
Alex Mason 2011년 8월 17일
need to expand on it now, becasue if there is no discharge in the frame I dont want it to then count the next biggest thing as a discharge. I guess just using an if statement and threshold will do this (ie all the discharge areas are likely to be more than say 2000 pixels)
also need to make sure it doesnt count the same discharge twice.

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


Walter Roberson
Walter Roberson 2011년 8월 16일
imdilate(), then bwlabel(), then regionprops(), and discard the areas whose height is below some threshold (not tall enough to be a streak.) regionprops() will have returned the centroid as well.
  댓글 수: 7
Sean de Wolski
Sean de Wolski 2011년 8월 16일
structuring elements are just kernels for a (special) convolution. (at least that's my understanding of them). You can always use a binary matrix instead of a strel
imdilate(bw,[0 1 0; 1 1 1; 0 1 0]); % etc.
Walter Roberson
Walter Roberson 2011년 8월 16일
Unfortunately I never studied convolution theory. :(

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


Alex Mason
Alex Mason 2011년 8월 16일
Will try this out
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2011년 8월 16일
doc imdilate
doc strel
doc bwconncomp
doc regionprops

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

Community Treasure Hunt

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

Start Hunting!

Translated by