MATLAB Answers

0

Detecting multiple object in an image

Asked by Felipe Souza on 31 Mar 2019
Latest activity Commented on by Felipe Souza on 2 Apr 2019
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 Comments

Show 1 older comment
Original Image
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

Sign in to comment.

Products


Release

R2017a

1 Answer

Answer by Shunichi Kusano on 2 Apr 2019

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 Comment

Thanks a lot!
I am going to give a look on the link you posted

Sign in to comment.