how to create a region of interest in simulink
古いコメントを表示
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

採用された回答
その他の回答 (2 件)
Image Analyst
2013 年 11 月 26 日
0 投票
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 件のコメント
Kean
2013 年 11 月 26 日
Image Analyst
2013 年 11 月 26 日
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
2013 年 11 月 26 日
Image Analyst
2013 年 11 月 26 日
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
2013 年 11 月 26 日
Image Analyst
2013 年 11 月 26 日
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
2013 年 11 月 26 日
Kean
2013 年 11 月 26 日
Image Analyst
2013 年 11 月 26 日
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
2013 年 11 月 26 日
Kean
2013 年 11 月 26 日
Kean
2013 年 11 月 26 日
Image Analyst
2013 年 11 月 26 日
Saving as PNG would be preferable and faster for us to view them.
Kean
2013 年 11 月 26 日
Kean
2013 年 11 月 27 日
Image Analyst
2013 年 11 月 27 日
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
2013 年 11 月 27 日
Image Analyst
2013 年 11 月 27 日
編集済み: Image Analyst
2013 年 11 月 27 日
No function, just the operation:
thresholdValue = 3500; % Whatever....
elementsAboveThreshold = signal > thresholdValue;
Kean
2013 年 11 月 27 日
Kean
2013 年 11 月 27 日
Kean
2013 年 12 月 1 日
Kean
2013 年 12 月 3 日
0 投票
4 件のコメント
Sean de Wolski
2013 年 12 月 3 日
Sure, add another Element SUM block in before the comparison.
Kean
2013 年 12 月 3 日
Sean de Wolski
2013 年 12 月 3 日
Use a selector block to "select" the first 10 elements in the signal before the sum block
Kean
2013 年 12 月 4 日
カテゴリ
ヘルプ センター および File Exchange で Computer Vision with Simulink についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
