Find Image/Reference Image within Image

2 次查看(过去 30 天)
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.

回答(1 个)

Jaynik
Jaynik 2024-1-25
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.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by