Azzera filtri
Azzera filtri

Find Image/Reference Image within Image

4 visualizzazioni (ultimi 30 giorni)
Taru
Taru il 25 Gen 2022
Risposto: Jaynik il 25 Gen 2024
Hi All, I need to find the icons displayed in a pdf file and output them in a tabular format. I have turned the pdf file to png to be able to do some image processing on the image.
I need to use the reference icons to detect the status of the vehicle for each test and output that result in table format. The tests vary depending if it is a mechanical report or it states its a hybrid report therefore there may sometimes be additional columns to analyse. I have also attached the png versions of the reference icons on their own.
I require a table such as this example;
(col1) "Green" ,(col2) "Green" , (col3) "Orange" etc.....
It would be additionally helpul if it could run through each of the files also and output the results in a master table if possible.

Risposte (1)

Jaynik
Jaynik il 25 Gen 2024
Hi Taru,
I assume that the specification sheet template remains the same. If that is the case, instead of using image processing or machine learning algorithms, you can simply set a template using coordinates of each icon.
As you have different images for the hybrid and mechanical report, you can easily determine whether to generate a column for hybrid or mechanical. Below is a sample code you can use to get started. I assume the "Standard Mechanical Report" for now:
finalAns = strings(2,3);
col1_top = [426, 243]; % Setting coordinates of each icon
col1_bottom = [434, 800]; % These should be set appropriately
col2_top = [891, 262];
col2_bottom = [895, 552];
col3_top = [1119, 259];
col3_bottom = [1119, 542];
coordsToCheck = [col1_top; col1_bottom; col2_top; col2_bottom; col3_top; col3_bottom];
img = imread("sheet1.png"); % Name of your specs seet
% if else statement to check if mechanical or hybrid
for i=1:size(coordsToCheck, 1)
y = ceil(i / size(finalAns, 1));
x = i - (y - 1) * size(finalAns, 1);
rgbValues = double(squeeze(img(coordsToCheck(i,2), coordsToCheck(i,1), :))) / 255;
rgbArray = reshape(rgbValues, [1, 1, 3]);
hsv = rgb2hsv(rgbArray);
hueDegrees = hsv(1) * 360;
saturationPercent = hsv(2) * 100;
valuePercent = hsv(3) * 100;
% Set colors based on hue and rgb values
if (hueDegrees <= 30 && hueDegrees >= 25)
finalAns(x,y) = "Orange";
elseif (hueDegrees <= 92 && hueDegrees >= 75)
finalAns(x,y) = "Green";
elseif (hueDegrees >= 345)
finalAns(x,y) = "Red";
elseif (rgbValues(1) == 0)
finalAns(x,y) = "Black";
else
finalAns(x,y) = "White";
end
end
I hope this works for you, feel free to reach out if you have any other queries regarding the code.

Community Treasure Hunt

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

Start Hunting!

Translated by