Automating the process of comparing between multiple images based on some conditions

4 Ansichten (letzte 30 Tage)
I have 4 handwritten images (I have their unique centroids and radius range in a table as a .mat file) and standard images from A to Z.
I want to compare the unique centroids and also the radius range of each 4 handwritten images with standard images based on a condition. The comparison is shown below in the fig. :
As you can see I have compared the handwritten image 1 with Standard image A, then handwritten image 2 is compared with standard image A, then handwritten image 3 is compared with Standard image A, then handwritten image 4 is compared with standard image A.
Next, handwritten image 1 is compared with Standard image B, then handwritten image 2 is compared with standard image B, then handwritten image 3 is compared with Standard image B, then handwritten image 4 is compared with standard image B.
Likewise, it goes upto standard image Z.
I was trying to automate this process using functions, but could not figure it out.
Also, I want to see the output in a table form like this:
Hanwritten Standard Score
  1. image 1 std A 3
  2. image 2 std A 0
  3. image 3 std A 6
  4. image 4 std A 8
--------------------------------------------------------------------------------------------
5. image 1 std B 6
6. image 2 std B 2
7. image 3 std B 4
8. image 4 std B 2
Here is the code to compare between a handwritten image and a standard image, and in result showing the similarity score for the matching results:
Also if possible I want a range of distance threshold between 10 - 15 and radius threshold between 2 - 5.
load('result_table_stdA.mat'); %Standard image
load('result_table_8827.mat'); %Handwritten image
% Define Thresholds
distance_threshold = 10;
radius_threshold = 2;
% Initialize Similarity Score
similarity_score = 0;
% Handwritten Image
for i = 1:height(result_table_8827)
current_centroid = result_table_8827{i, 'Unique_Centroids'};
current_x_coordinate = current_centroid(1); % X coordinate
current_y_coordinate = current_centroid(2); % Y coordinate
current_radius_range = result_table_8827.Range(i, :);
% Standard Image
for j = 1:height(result_table_stdA)
centroid1 = result_table_stdA{j, 'Unique_Centroids'};
centroid1_x_coordinate = centroid1(1); % X coordinate
centroid1_y_coordinate = centroid1(2); % Y coordinate
radius_range1 = result_table_stdA.Range(j, :);
% Check if distance and radius range match
if pdist2([current_x_coordinate, current_y_coordinate], [centroid1_x_coordinate, centroid1_y_coordinate]) <= distance_threshold && abs(current_radius_range(1) - radius_range1(1)) <= radius_threshold && abs(current_radius_range(2) - radius_range1(2)) <= radius_threshold
similarity_score = similarity_score + 1;
break; % Move to the next centroid in table
end
end
end
% Display Similarity Scores
disp(similarity_score);

Antworten (1)

VINAYAK LUHA
VINAYAK LUHA am 16 Jul. 2024
Bearbeitet: VINAYAK LUHA am 16 Jul. 2024
Hi Saumalya,
I understand that you have two sets of image data, labeled "Handwritten" and "Standard," and you wish to compare each image data in the "Handwritten" set with each image data in the "Standard" set. Additionally, you want to compile the results into the specified table format.
Here's a structured approach:
  1. Wrap your comparison logic in a function, say "compareImages" that takes one "Handwritten" image ".MAT" data and one "Standard" image data ".MAT" file path names as arguments and returns a "similarity score".
  2. Initialize the "results" table with the required column names.
  3. Iterate over the "Standard" images data, and within that loop, iterate over the "Handwritten" images data, performing comparisons and storing the results in the table.
Assuming that the "Handwritten" and "Standard" image data ".MAT" files are stored in folders - "Handwritten" and "Standard" respectively, here is the code snippet on how to implement step -3.
% Folders containing the .MAT files
handwrittenFolder = 'Handwritten'; % Replace with actual path
standardFolder = 'Standard'; % Replace with actual path
% Read .MAT files from the folders
handwrittenFiles = dir(fullfile(handwrittenFolder, '*.mat'));
standardFiles = dir(fullfile(standardFolder, '*.mat'));
% Initialize the result table
results = table('Size', [0, 3], 'VariableTypes', {'string', 'string', 'double'}, 'VariableNames', {'Standard', 'Handwritten', 'Score'});
% Loop through the standard .MAT files
for j = 1:length(standardFiles)
standardDataFileName = fullfile(standardFolder, standardFiles(j).name);
for i = 1:length(handwrittenFiles)
handwrittenDataFileName = fullfile(handwrittenFolder, handwrittenFiles(i).name);
% Compare images and get the score
score = compareImages(handwrittenDataFileName, standardDataFileName);
% Store the result in the table
results = [results; {handwrittenFiles(i).name,standardFiles(j).name, score}]
end
end
Additionally, you can paramterize "radius threshold" and "distance threshold" variables in the comparison function and use MATLAB's random number generation to select random values within the specified ranges and pass them as arguments to the comparison function.
For more details on the functions used, refer to the following documentations -
I hope this helps.
Regards,
Vinayak Luha

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by