Finding coordinates with image processing
31 views (last 30 days)
Show older comments
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
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?
- Centroid (x,y) of each of the 3 blobs like you'd get from regionprops(mask, 'Centroid')??
- (x,y) coordinates from each blob like you'd get from regionprops(mask, 'PixelList')?
- Both of the above?
Answers (1)
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
Turlough Hughes
on 26 Jun 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
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.
- Centroid (x,y) of each of the 3 blobs like you'd get from regionprops(mask, 'Centroid')??
- (x,y) coordinates from each blob like you'd get from regionprops(mask, 'PixelList')?
- Bounding box?
- 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.
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!