Finding coordinates with image processing

26 vues (au cours des 30 derniers jours)
Erkan Karaoglu
Erkan Karaoglu le 15 Juin 2021
Commenté : Image Analyst le 26 Juin 2021
Hello to everyone . I want to detect the faulty panels. But how can I show its coordinates. Can you help me. Thanks.
% 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")
  4 commentaires
Erkan Karaoglu
Erkan Karaoglu le 15 Juin 2021
I got this result by copy-pasting. I don't know how to improve the program.
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 = 'Adsız.png';
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);
Image Analyst
Image Analyst le 25 Juin 2021
Not sure what you mean. Plus your code above won't work since it takes just the largest blob and you have 3. Exactly what do you want?
  1. Centroid (x,y) of each of the 3 blobs like you'd get from regionprops(mask, 'Centroid')??
  2. (x,y) coordinates from each blob like you'd get from regionprops(mask, 'PixelList')?
  3. Both of the above?

Connectez-vous pour commenter.

Réponses (1)

Turlough Hughes
Turlough Hughes le 15 Juin 2021
You could use the regionprops function to get the centroids. See the following example:
% This just sets up an image for demo
I = false(200);
I(50:60,50:60)=1;
I(100:110,160:170)=1;
imshow(I,'border','tight')
Then the solution is actually just:
p = regionprops(I,'Centroid'); % centroid's locations for each component detected in the image
and you can plot the results as follows:
figure(), imshow(I,'border','tight'), hold on,
plot(p(1).Centroid(1),p(1).Centroid(2),'or','MarkerFaceColor','r')
plot(p(2).Centroid(1),p(2).Centroid(2),'ob','MarkerFaceColor','b')
Note that this uses pixel coordinates (regularly used in image processing)- this is where the x and y position correspond to the column and row numbers of your image... i.e. coordinate (1,1) is the center of the upperleftmost pixel in your image and the y-axis points vertically downwards. Consider the outcome when you plot on a seperate figure that is not an image.
  6 commentaires
Turlough Hughes
Turlough Hughes le 26 Juin 2021
If you get errors you should show what they are to help people answer your questions. My answer was for the image you provided in your original question - the new image you provided now has four components because the white border is also a component so I omit that in plotting the final results. You can do the following to get the pixel positions:
I = imread('Adsiz_3.jpeg'); % read in the image (rgb)
BW =sum(I,3)>200; % convert to binary
p = regionprops(BW,'Centroid'); % get centroids for each component (there are 4)
% Show resulting image and positions
imshow(BW,'border','tight')
hold on
mColors = {'r','g','b'} ; % Different colors to distinguish the plots
arrayfun(@(x) ...
plot(p(x).Centroid(1),p(x).Centroid(2),'+','Color',mColors{x-1},'LineWidth',3,'MarkerSize',20)...
,2:numel(p))
Note, however, that since Adsiz_3.jpeg is cropped, the references to position are now different compared with the original image (the one at the top of this question). Depending on what you are trying to do you may need to give some particular attention to that point.
Image Analyst
Image Analyst le 26 Juin 2021
@Erkan Karaoglu, plus you still haven't answered my questions up top where I asked what finding the coordinates means to you. Please answer.
  1. Centroid (x,y) of each of the 3 blobs like you'd get from regionprops(mask, 'Centroid')??
  2. (x,y) coordinates from each blob like you'd get from regionprops(mask, 'PixelList')?
  3. Bounding box?
  4. All of the above?
I don't see any need for all that binary morphology (opening, closing, dilating). And no reason for cropping unless you just want to zoom in. If you crop you'll have different coordinates in the cropped and uncropped image. Actually even in the original, uncropped image it appears you have no calibration from pixels to any kind of real world coordinate system, like in meters or something. And from your other post it looked like the camera was just pointed at some crazy angle into the room so getting real world coordinates (x, y, and z from some known, fixed landmark in the scene) is going to be tricky.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by