MATLAB Answers

Finding coordinates with image processing

53 views (last 30 days)
Erkan Karaoglu
Erkan Karaoglu on 15 Jun 2021
Commented: Image Analyst on 26 Jun 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 Comments
Image Analyst
Image Analyst on 25 Jun 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?

Sign in to comment.

Answers (1)

Turlough Hughes
Turlough Hughes on 15 Jun 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 Comments
Image Analyst
Image Analyst on 26 Jun 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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!