Find Image/Reference Image within Image

조회 수: 1 (최근 30일)
Taru
Taru 2022년 1월 25일
답변: Jaynik 2024년 1월 25일
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
yanqi liu
yanqi liu 2022년 1월 26일
yes,sir,may be use color and shape to make object match

댓글을 달려면 로그인하십시오.

답변 (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