Detecting multiple object in an image

9 ビュー (過去 30 日間)
Felipe Souza
Felipe Souza 2019 年 3 月 31 日
コメント済み: Felipe Souza 2019 年 4 月 2 日
Hello,
I am working on a project where I have to detect photovoltaic modules using infrared images.
I am using a template image to detect the modules but I can only detect one. What should I do to detect all the modules?
I do not have a lot of experience in programming but I am really trying.
  4 件のコメント
Felipe Souza
Felipe Souza 2019 年 4 月 1 日
編集済み: Felipe Souza 2019 年 4 月 1 日
Template
Felipe Souza
Felipe Souza 2019 年 4 月 1 日
clear all; close all; clc;
%% READING THE RGB IMAGE
A = imread('Teste.jpg');
imshow(A);
%% CONVERTING RGB IMAGE TO GRAYSCALE FORMAT
A_gray = rgb2gray(A);
imshow(A_gray);
%% CONVERTING IMAGE TO DOUBLE FORMAT
A_gray = im2double(A_gray);
imshow(A_gray);
%% CONVERTING THE GRAYSCALE IMAGE TO BINARY FORMAT
otsu_level = graythresh(A_gray);
A_otsu_thresh = im2bw(A_gray, otsu_level);
imshow(A_otsu_thresh);
%% DETECTING OBJECTS IN THE IMAGE
label=bwlabel(A_otsu_thresh);
max(max(label))
for j=1:max(max(label))
im1 = (label==j);
figure(2), subplot(6,6,j);imshow(im1); title(j);
j= j+1;
end
%% CORRELATION
[Ir Ic]=size(A_gray);
T1 = imread('Template.jpg'); %read template of the image
T = rgb2gray(T1);
imshow(T);
[Tr Tc]=size(T);
R=normxcorr2(T,A_gray); %find normalize cross correlation
R=imcrop(R,[Tc Tr Ic Ir]); %crop extra pixels
[row column value] = find(R==(max(max(R)))) %find the coordinates where maximum correlation exists
RGB=insertShape(A_gray,'rectangle',[column row Tc Tr], 'LineWidth',3); %create a box around maximum match
imshow(RGB);
% RIGHT HERE I WOULD LIKE TO COMPARE THE OBJECTS WITH A NORMAL MODULE
% IN ORDER TO FIND DEFECT MODULES AND LOCATE THEIR POSITIONS

サインインしてコメントする。

回答 (1 件)

Shunichi Kusano
Shunichi Kusano 2019 年 4 月 2 日
You select only one of highly correlated pixels, because you find the maximum correlation by "find(R==(max(max(R))))". In order to detect some of them, you need to select peaks. For that, the following link is useful.
By the way, you can use max(R(:)) instead of max(max(R)). In addition, j = j + 1 in the for loop is not needed here. In the for loop, the value of j is automatically incremented according to what you indicated as 1:max(label(:)).
  1 件のコメント
Felipe Souza
Felipe Souza 2019 年 4 月 2 日
Thanks a lot!
I am going to give a look on the link you posted

サインインしてコメントする。

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by