Finding location with image processing method
Mostra commenti meno recenti
clc; clear all
%% 1
I=imread('erkan_1.jpeg'); %Reading Image
gray=im2gray(I); %Converting RGB Image to Grayscale
J = imnoise(gray,'salt & pepper',0.01);
K = medfilt2(J);
%S=imsharpen(K);
figure,imshow(I)
title("Original Image")
% gray2=imadjust(gray);
figure; imhist(K) %Checking the histogram of the gray Image
title("Grayscale Histogram")
figure,imshow(gray)
title("Grayscale")
Binary = im2bw(gray,0.8); %Creating Binary Image with Threshold Value
% figure, imshowpair(Binary_2,Binary,"montage"),title("Grayscale vs Binary") %Showing Grayscale and Binary Photos
Binary=uint8(Binary); %Converting the Binary Photo to uint8 style to change matrix values
Binary(Binary>0) = 255; %Changing the black and white colours
figure,imshow(Binary)
Result=I+Binary; %We know that sum of the matrix value and 255 give us 255. Therefore we can use it.
Result(Result==255)=0; %Then changing black and white places again
% figure,imshow(Result) %Showing the result
se = strel('disk',1); %Creating a pattern to dilation
BW22 = imdilate(Binary,se); %Dilation to selected panels to see lines more smooth
Result_2=I+BW22;
Result_2(Result_2==255)=0;
text1='As seen, the image looks more clear with dilation.';
position1 = [5 60];
RGB_1 = insertText(Result_2,position1,text1,'FontSize',15);%Implementing the text to image
% figure,imshow(Result) %Showing the result
figure, imshowpair(Result,RGB_1,"montage"),title("Before Dilation vs After Dilation")
%As seen, the image looks more clear with dilation
% COUNTING
afteropening=imopen(BW22,se); %It fills the holes
afterclosing=imclose(afteropening,se); %Deletes the small noises
[L,num]=bwlabel(afterclosing,4); %Taking number of the panels
position2 = [1 50];
text2 = ['There are ',num2str(num),' solar panels which not work.'];
RGB_2 = insertText(Result_2,position2,text2,'FontSize',18);%Implementing the text to image
figure, imshow(RGB_2)
title("RESULT")
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
%===============================================================================
% Get the name of the first image the user wants to use.
baseFileName = 'erkan_1.jpeg';
folder = fileparts(which(baseFileName)); % Determine where demo folder is (works with all versions).
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%=======================================================================================
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Display the original image.
subplot(2, 3, 1);
imshow(rgbImage, []);
axis on;
caption = sprintf('Original Color Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Coordination', 'NumberTitle', 'Off')
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = rgbImage(:, :, 1); % Take red channel.
end
% Display the image.
subplot(2, 3, 2);
imshow(grayImage, []);
axis on;
title('Gray Image', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
drawnow;
% Display the histogram of the image.
subplot(2, 3, 3);
histogram(grayImage, 256);
title('Histogram of Gray Image', 'FontSize', fontSize, 'Interpreter', 'None');
grid on;
drawnow;
%=======================================================================================
binaryImage = grayImage < 240;
% Keep only the largest blob.
binaryImage = bwareafilt(binaryImage, 1);
% Display the masked image.
subplot(2, 3, 3);
imshow(binaryImage, []);
axis on;
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
drawnow;
% Compute the Euclidean Distance Transform
edtImage = bwdist(~binaryImage);
I = imread('Adsız.png'); % black/white image you provided which has RGB format
BW = logical(sum(I,3)); % nonzero pixels are set to 1, otherwise 0.
p = regionprops(BW,'Centroid');
imshow(BW)
hold on
mColors = {'r','g','cyan'};
arrayfun(@(x) ...
plot(p(x).Centroid(1),p(x).Centroid(2),...
'o','MarkerFaceColor',mColors{x},'MarkerSize',10)...
,1:numel(p))
7 Commenti
Erkan Karaoglu
il 24 Giu 2021
Erkan Karaoglu
il 24 Giu 2021
Image Analyst
il 25 Giu 2021
How do you want to show them? It looks like you already are, by having a map with a big white spot where the object of interest is. Is that now what you want? Do you want a big red crosshairs centered on the blob centroid? Please be specific.
Erkan Karaoglu
il 26 Giu 2021
Image Analyst
il 26 Giu 2021
I still don't understand. regionprops() can give you both the centroid and bounding box of all blobs in the image "automatically". That is what you said you want, so why is there still a problem? Also you forgot to attach 'Tuzak.jpg'.
And why are you adding noise to your original image? That can't help.
Erkan Karaoglu
il 26 Giu 2021
What can be used as a spatial reference? Is a small amount of user-interaction acceptable? Is the camera position and framing always repeatable? Are we only concerned with the central rack of 18 panels, or do we need to map all panels in view? Is it of any concern to identify which parts of the panel were bad, or just the entire panel?
Risposta accettata
Più risposte (1)
Given that this was probably done by drone, I'm going to assume that framing and camera position are not practically repeatable. I'm going to assume that we're only interested in one particular rack per image.
Consider the example:
panelsperrack = [2 9]; % expected rack layout
% read image
inpict = rgb2gray(imread('erkan.jpg'));
s = [size(inpict,1) size(inpict,2)];
% manually get location of this rack
% just specify the rack extents with 4 points
imshow(inpict)
P = drawpolygon();
rpos = P.Position;

% need to enforce vertex ordering to maintain orientation
d = rpos-mean(rpos);
a = atan2(-d(:,2),d(:,1));
[~,idx] = sort(a,'ascend');
rpos = rpos(idx,:);
% get transform
fpos = [0 500; 1000 500; 1000 0; 0 0];
TF = fitgeotrans(rpos,fpos,'projective');
% transform and crop the image to the control point extents
[rpict outref] = imwarp(inpict,TF);
[x y] = transformPointsForward(TF,rpos(:,1),rpos(:,2));
[x y] = worldToIntrinsic(outref,x,y);
cpos = [min(x) min(y) max(x)-min(x) max(y)-min(y)];
rpict = imcrop(rpict,cpos); % rectified ROI image

% do whatever you need to do to isolate the hot spots
% i'm just going to do something simple for sake of example
hotpict = rpict>200;
% find row-major linear index of bad panel for each hot object
S = regionprops(hotpict,'centroid');
C = vertcat(S.Centroid);
badrow = ceil(panelsperrack(1)*C(:,2)/size(rpict,1));
badcol = ceil(panelsperrack(2)*C(:,1)/size(rpict,2));
badidx = sub2ind(fliplr(panelsperrack),badcol,badrow)
The output is:
badidx =
15
15
15
Which could be handled however you choose for reporting purposes.
Categorie
Scopri di più su Image Processing Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

