# Comparing multiple images ( via edge detection or strongest gradient between dark and light)

5 views (last 30 days)
Arb2493 on 7 May 2020
Commented: Rena Berman on 22 Jul 2020 at 18:48
Hello guys,
first of all : i am very new to matlab so dont blame me for asking.
I want to compare some pictures ( 5 pictures or so ).I am testing a light,every hour i take a photo and then compare them to see if the'cut-off' did move. And if the 'cut off' moves, I'd like to see how much it shifted.
Every little adive would help me !
( I uploadet the picutre. In my test, the pictures will loke the same. But maybe afters 3 hours the 'cut-off will shift minimal. And thats what i wanna se. Like if i could get a number in the end like 2 == It shifted 2 millimeters.)
THX GUYS !

Rik on 7 Jul 2020
Comparing multiple images ( via edge detection or strongest gradient between dark and light)
Hello guys,
first of all : i am very new to matlab so dont blame me for asking.
I want to compare some pictures ( 5 pictures or so ).I am testing a light,every hour i take a photo and then compare them to see if the'cut-off' did move. And if the 'cut off' moves, I'd like to see how much it shifted.
Every little adive would help me !
( I uploadet the picutre. In my test, the pictures will loke the same. But maybe afters 3 hours the 'cut-off will shift minimal. And thats what i wanna se. Like if i could get a number in the end like 2 == It shifted 2 millimeters.)
THX GUYS !
Rena Berman on 22 Jul 2020 at 18:48

Image Analyst on 7 May 2020
I don't know what the "cut-off" is. Is it the shadow line? Do you want the row number of the shadow for every column in the image? Something like
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels == 3
grayImage = rgb2gray(grayImage);
end
binaryImage = grayImage < someValue; % For example someValue = 100 or whatever.
for col = 1 : columns
t = find(binaryImage(:, col), 1, 'first')
if ~isempty(t)
end
end
grid on;

Image Analyst on 11 May 2020
Try this:
clc; % Clear the command window.
fprintf('Beginning to run %s.m.\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
baseFileName1 = 'hdg.png';
fullFileName1 = fullfile(pwd, baseFileName1);
[rows, columns, numberOfColorChannels] = size(grayImage1)
if numberOfColorChannels == 3
grayImage1 = rgb2gray(grayImage1);
end
% Display image.
subplot(2, 3, 1);
imshow(grayImage1, []);
impixelinfo
title(baseFileName1, 'FontSize', fontSize);
% Threshold the image.
thresholdValue = 125;
binaryImage = grayImage1 < thresholdValue;
% Take largest blob.
binaryImage = bwareafilt(binaryImage, 1);
% Do a morphological opening to get rid of grid lines.
binaryImage = imopen(binaryImage, true(3));
% Display image.
subplot(2, 3, 4);
imshow(binaryImage, []);
impixelinfo
title(baseFileName1, 'FontSize', fontSize);
for col = 1 : columns
t = find(binaryImage(:, col), 1, 'last')
if ~isempty(t)
end
end
baseFileName2 = 'hdg1.png';
fullFileName2 = fullfile(pwd, baseFileName2);
[rows, columns, numberOfColorChannels] = size(grayImage2)
if numberOfColorChannels == 3
grayImage2 = rgb2gray(grayImage2);
end
% Display image.
subplot(2, 3, 2);
imshow(grayImage2, []);
impixelinfo
title(baseFileName2, 'FontSize', fontSize);
% Threshold the image.
binaryImage = grayImage2 < thresholdValue;
% Take largest blob.
binaryImage = bwareafilt(binaryImage, 1);
% Do a morphological opening to get rid of grid lines.
binaryImage = imopen(binaryImage, true(3));
% Display image.
subplot(2, 3, 5);
imshow(binaryImage, []);
impixelinfo
title(baseFileName2, 'FontSize', fontSize);
for col = 1 : columns
t = find(binaryImage(:, col), 1, 'last');
if ~isempty(t)
end
end
subplot(2, 3, 3);
hold on;
grid on;
xlabel('Row', 'FontSize', fontSize);
ylabel('Column', 'FontSize', fontSize);
legend('image 1', 'image 2', 'Location', 'northwest');
% The images are not the same size for some strange reason so we can't subtract the arrays until we match their sizes
else
end
% Plot the difference.
subplot(2, 3, 6);
plot(diffRows, 'b-')
grid on;
xlabel('Row', 'FontSize', fontSize);
ylabel('Vertical Difference', 'FontSize', fontSize);
title('Difference in Shadow Locations', 'FontSize', fontSize);
% Maximize figure.
g = gcf;
g.WindowState = 'maximized'

Image Analyst on 20 May 2020
You put the axis ij command after the plot() command:
% Plot the difference.
subplot(2, 3, 6);
plot(diffRows, 'b-')
axis ij;
grid on;
xlabel('Row', 'FontSize', fontSize);
ylabel('Vertical Difference', 'FontSize', fontSize);
title('Difference in Shadow Locations', 'FontSize', fontSize);
Arb2493 on 7 Jul 2020
thx for the response.
I have a problem with these pictures. The code doesnt recognize the shadow line ?
madhan ravi on 7 Jul 2020
You must be kidding right? You deleted the question!!