how to create a region of interest in simulink
Ältere Kommentare anzeigen
I am trying to count the number of railroad ties in a video using simulink. The thought is to use sobel edge detection on each video frame. The railroad tie ends up being the background in the binary. Then use bottom-hat to apply a mask to the tie with an area say 15 pixels tall by 60 pixels wide. Then when the complete mask is in the region of interest it detects and counts the tie.
Attached is a frame from the video. I would like to create a rectangular region of interest x1=110, y1=105, x2=110, y2=75, x3=210, y3=75, x4=210, y4=105.
Does anyone know how to create a region of interest? I have looked at the examples in Matlab and I can't seem to figure it out.
Also, I am very new to Matlab/Simulink and not a computer scientist, vision/image scientist. So, if anyone has other suggestions I am very open to suggestions or if anyone thinks what I am doing can't be accomplished through this process then I am all ears as well.
Thanks

Akzeptierte Antwort
Weitere Antworten (2)
Image Analyst
am 26 Nov. 2013
0 Stimmen
I don't know how to do it in Simulink, but if you can write custom MATLAB code in a Simulink block, what I'd do it first sum the image vertically and detect the two rails. Then get rid of those columns - remove them from the image. Then so some sort of texture filter such as stdfilt() or imgradient() to get a texture image. Then sum that horizontally. High sum regions will be gravel/rocks. Low sum regions will be railroad ties. Then just threshold and pass the binary vector into bwlabel to count the ties, or pass into regionprops if you want to determine how many ties and fractions of ties there are. Not too hard. Can you code that up? If not let me know and I'll help you.
21 Kommentare
Kean
am 26 Nov. 2013
Image Analyst
am 26 Nov. 2013
My algorithm counts ties in each frame, not the whole video. You're going to have to do something else to get the whole video. If you just stitch one frame to the earlier and later adjacent frame, do you get a continuous image? Or are the jumps/breaks/discrepancies in it? Is there any tie, or part of a tie, that does not show up in any frame at all? Because there might be a small time lapse between frames where the ties moved along but didn't get an image snapped of them during that inter-frame time.
Kean
am 26 Nov. 2013
Image Analyst
am 26 Nov. 2013
Well that's the better situation than missing some part. Now to count frames you only need to increment the "tie count" when you have one complete (not partial) tie. And you only need to count the first complete tie that you see at the top of the frame. You do not need to count any below that because they've already been counted on prior frames. This simplifies the code a lot. You don't need to detect partial ties or keep track when a tie comes or goes. You simply need to count it when you have a complete tie, and the tie is in a different place than the prior frame (to account for aliasing). Of course there is a degenerate case where you're snapping a photo at the exact rate where the speed is such that it seems the ties don't move at all. I'm sure you've seen car commercials where it looks like the wheel spokes go backwards or stay still even though the car is moving forward.
Kean
am 26 Nov. 2013
Image Analyst
am 26 Nov. 2013
Did you do the code to get horizontal and vertical profiles yet? The first step is to find the ties, then the second step is to track/label them. To do that you find the rails and just look inside the rails and crop off the left and right chunks of the image. Then do a texture filter and collape horizontally and look for high texture areas and low texture areas. It should look like a rectangle wave. Then find the low texture areas - those are the ties presumably. Did you do any of that yet?
Kean
am 26 Nov. 2013
Kean
am 26 Nov. 2013
Image Analyst
am 26 Nov. 2013
I don't use Simulink and an not sure if you can have a block in Simulink where you execute MATLAB code. If you can, then I can continue to help you, otherwise there's no point.
Kean
am 26 Nov. 2013
Kean
am 26 Nov. 2013
Kean
am 26 Nov. 2013
Image Analyst
am 26 Nov. 2013
Saving as PNG would be preferable and faster for us to view them.
Kean
am 26 Nov. 2013
Kean
am 27 Nov. 2013
Image Analyst
am 27 Nov. 2013
It looks good! I'd threshold it around 3000 or 4000. Then you might have to do a little clean up in case you get tiny little extra peaks, like around x=100.
Kean
am 27 Nov. 2013
Image Analyst
am 27 Nov. 2013
Bearbeitet: Image Analyst
am 27 Nov. 2013
No function, just the operation:
thresholdValue = 3500; % Whatever....
elementsAboveThreshold = signal > thresholdValue;
Kean
am 27 Nov. 2013
Kean
am 27 Nov. 2013
Kean
am 1 Dez. 2013
Kean
am 3 Dez. 2013
0 Stimmen
4 Kommentare
Sean de Wolski
am 3 Dez. 2013
Sure, add another Element SUM block in before the comparison.
Kean
am 3 Dez. 2013
Sean de Wolski
am 3 Dez. 2013
Use a selector block to "select" the first 10 elements in the signal before the sum block
Kean
am 4 Dez. 2013
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
