0
画像をテストして同じ画像であるかどうかを確認するプロジェクト用のプログラムを作成しました。私は使用している画像が同じ方法でスタイルされているので、相関関係を使うことにしました。これで、私はこの時点までにすべてを処理することができました。MatLab - 相関関係に基づいて画像の配列を作成する
今度は、画像の配列をもう一度作成しますが、今回は相関の順に画像を作成します。たとえば、50ペンスのコインをテストしていて、50ペンスのコインに対して50枚の画像をテストする場合、最も高い5つの相関を配列に格納し、後で使用することができます。しかし、配列の各項目が複数の変数を持つ必要があるので、これを行う方法がわかりません。これは、イメージのイメージの場所/名前と相関のパーセンテージになります。
%Program Created By Ben Parry, 2016.
clc(); %Simply clears the console window
%Targets the image the user picks
inputImage = imgetfile();
%Targets all the images inside this directory
referenceFolder = 'M:\Project\MatLab\Coin Image Processing\Saved_Images';
if ~isdir(referenceFolder)
errorMessage = print('Error: Folder does not exist!');
uiwait(warndlg(errorMessage)); %Displays an error if the folder doesn't exist
return;
end
filePattern = fullfile(referenceFolder, '*.jpg');
jpgFiles = dir(filePattern);
for i = 1:length(jpgFiles)
baseFileName = jpgFiles(i).name;
fullFileName = fullfile(referenceFolder, baseFileName);
fprintf(1, 'Reading %s\n', fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray);
firstImage = imread(inputImage); %Reading the image
%Converting the images to Black & White
firstImageBW = im2bw(firstImage);
secondImageBW = im2bw(imageArray);
%Finding the correlation, then coverting it into a percentage
c = corr2(firstImageBW, secondImageBW);
corrValue = sprintf('%.0f%%',100*c);
%Custom messaging for the possible outcomes
corrMatch = sprintf('The images are the same (%s)',corrValue);
corrUnMatch = sprintf('The images are not the same (%s)',corrValue);
%Looping for the possible two outcomes
if c >=0.99 %Define a percentage for the correlation to reach
disp(' ');
disp('Images Tested:');
disp(inputImage);
disp(fullFileName);
disp (corrMatch);
disp(' ');
else
disp(' ');
disp('Images Tested:');
disp(inputImage);
disp(fullFileName);
disp(corrUnMatch);
disp(' ');
end;
imageArray = imread(fullFileName);
imshow(imageArray);
end