How can I load and plot the difference of a set of images to a reference image?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lea Kerciku
el 22 de Mzo. de 2021
Comentada: Lea Kerciku
el 22 de Mzo. de 2021
Hello,
my task is to create a graph showing how a set a of images change in relation to the reference image. For defining the difference I am using the Structural Similarity (SSIM) index. Now my problem is that my loop does not go through all image in the folder directory but only takes the first one. In order to make the graph I need to assign to each image the value of the SSIM index (ssimval) and plot it.
It would be very helpful if someone could show me what I am doing wrong in my code. Thank you!
Here is my code so far:
reference_img = imread('rock01b_noback.png'); %read reference img
folder = 'C:\Users\...';
morphimages = dir(fullfile(folder,'*.png')); %specify pattern of files in folder
for i = 1:length(morphimages)
imagename = morphimages(i).name;
fullimagename = fullfile(folder,imagename);
fprintf(1, 'Reading %s.\n', fullimagename);
imagearray = imread(fullimagename);
[ssimval,ssimmap] = ssim(imagearray,reference_img) %find ssim index for each img in folder
end
0 comentarios
Respuesta aceptada
Image Analyst
el 22 de Mzo. de 2021
Try this:
% Demo by Image Analyst.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
folder = 'C:\Users\lea\documents\Matlab\work\Images'; % Change to wherever your images are.
baseFileName = 'rock01b_noback.png';
fullFileName = fullfile(folder, baseFileName);
reference_img = imread(fullFileName); % read reference img
subplot(2, 2, 1);
imshow(reference_img);
title(baseFileName);
morphimages = dir(fullfile(folder,'*.PNG')); %specify pattern of files in folder
numImages = length(morphimages)
ssimval = zeros(1, numImages);
for k = 1 : length(morphimages)
baseImageName = morphimages(k).name;
fullImageName = fullfile(folder,baseImageName);
fprintf(1, 'Reading %d of %d : %s.\n', k, numImages, fullImageName);
subplot(2, 2, 2);
imageArray = imread(fullImageName);
if ~isequal(size(imageArray), size(imageArray))
fprintf('Skipping %d because it is not the same size as the reference image\n', baseImageName);
continue;
end
imshow(imageArray, []);
title(baseImageName);
ssimval(k) = ssim(imageArray, reference_img) %find ssim index for each img in folder
subplot(2, 2, 3:4);
plot(ssimval(1:k), 'b.-', 'LineWidth', 2, 'MarkerSize', 18);
drawnow;
grid on;
end
fprintf('Done running %s.m\n', mfilename);
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!