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