how get edge diffrance value between two images?

2 visualizzazioni (ultimi 30 giorni)
hosam
hosam il 8 Ott 2012
Risposto: Vidhi Agarwal il 10 Giu 2025
I am working on project to determine the crowded on the road using camera. the road may be(crowded/half crowded/empty).
My idea depend on get the difference between two images and get the edge of the difference and then calculate the value of the edge to determine the state of the road
>> full=imread('full.jpg');//read crowded road
>> one=imread('one.jpg'); //read one car on road
>> st=imread('st.jpg'); // read standard (empty) road
>> full=rgb2gray(full); //convert
>> one=rgb2gray(one);
>> dfull=full-st;// get the difference between two image
>> done=one-st;//get the difference between two image
>> efull=edge(dfull); //get the edge
>> eone=edge(done); // get the edge
Now I want get the value of efull and eone to compare between them
thanks

Risposte (1)

Vidhi Agarwal
Vidhi Agarwal il 10 Giu 2025
Hi @hosam,
To quantify the difference between the images (i.e., calculate a "value" from the edge maps like efull and eone), simply sum up the number of edge pixels might help you with the issue.
Updated code for the same is given below:
% Read images
full = imread('full.jpg');
one = imread('one.jpg');
st = imread('st.jpg');
% Convert to grayscale
full = rgb2gray(full);
one = rgb2gray(one);
st = rgb2gray(st);
% Compute difference from empty road
dfull = imabsdiff(full, st);
done = imabsdiff(one, st);
% Detect edges
efull = edge(dfull, 'Canny'); % You can also try 'Sobel', 'Prewitt', etc.
eone = edge(done, 'Canny');
% Count number of edge pixels
value_full = sum(efull(:));
value_one = sum(eone(:));
% Display results
fprintf('Edge pixel count - Full: %d\n', value_full);
fprintf('Edge pixel count - One Car: %d\n', value_one);
The interpretation for the same is value_full > value_one > empty image edge count. And based on thresholds you define, you can say:
  • If edge count ≈ 0 → Empty
  • If edge count ≈ value_one → Half-crowded
  • If edge count ≈ value_full → Crowded
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by