How to divide image into two regions?

Hi all, I have drawn a line on image and that line should divide image into two regions. when a car entering into line region it should detect car and count.I am working it for counting of cars in video. Please help me Thanks in advance

Answers (1)

Image Analyst
Image Analyst on 7 Jun 2016
Edited: Image Analyst on 7 Jun 2016
What is the "Line region"? Anyway, if you have the equation of a line, and the centroid of a blob, or any points in it, it's just simple algebra to determine if it's above or below the line. Just stick the centroid x, or any of the x values from the blob into the formula for the line and determine if the line's y is above or below the y centroid.
belowLine = yCentroid > (slope * xCentroid + intercept);
It's really trivial. What are you stuck on?

5 Comments

Here I am attaching the image of line which I have inserted. all I want is to count the vehicle if it crosses the line i.e., From right to left. Please help in writing a code.
The code I gave should work for that. Did you try it? You drew the line so I assume you have either the endpoints or the slope and intercept. And I'm assuming you have already detected the car and just need to know when it crosses the line. So you have everything you need. I can't write a full-blown turn key application for you. What's holding you back? Just a counter????
if belowLine
carCount = carCount + 1;
end
I have drawn a line on Image using below command but I am not able do anything with the code which you provided. Here is the code i have used to draw.
line = insertShape(I, 'line', [150,430,540,1050], 'LineWidth', 10);
I did not give you that code.
I actually mean I wrote the above "line" code to draw the line. what I need is to write the code on the "line". i.e., I'm confused to use the below code, which you've provided.
belowLine = yCentroid > (slope * xCentroid + intercept);

Sign in to comment.

Asked:

on 7 Jun 2016

Commented:

on 8 Jun 2016

Community Treasure Hunt

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

Start Hunting!