Get code result automatically

2 vues (au cours des 30 derniers jours)
Erkan Karaoglu
Erkan Karaoglu le 25 Juin 2021
Commenté : Erkan Karaoglu le 25 Juin 2021
I wrote this code. But I could not run this system automatically. How can I print the X and Y coordinate results and get the result automatically.
clc; clear all
I=imread('Tuzak.jpg'); %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")
xy = input('X ve Y koordinatlarını giriniz = : ')
x = xy(1)
y = xy(2)
if 0 < x && x < 58 && y < 120
uiwait(msgbox('1. Panel Arızalı'))
elseif 0 < x && x < 58 && y > 120
uiwait(msgbox('16. Panel Arızalı'))
end
if 58 < x && x < 118 && y < 118
uiwait(msgbox('2. Panel Arızalı'))
elseif 58 < x && x < 118 && y > 118
uiwait(msgbox('17. Panel Arızalı'))
end
if 118 < x && x < 179 && y < 118
uiwait(msgbox('3. Panel Arızalı'))
elseif 118 < x && x < 179 && y > 118
uiwait(msgbox('18. Panel Arızalı'))
end
if 179 < x && x < 238 && y < 113
uiwait(msgbox('4. Panel Arızalı'))
elseif 179 < x && x < 238 && y > 113
uiwait(msgbox('19. Panel Arızalı'))
end
if 247 < x && x < 306 && y < 111
uiwait(msgbox('5. Panel Arızalı'))
elseif 247 < x && x < 306 && y > 111
uiwait(msgbox('20. Panel Arızalı'))
end
if 306 < x && x < 371 && y < 106
uiwait(msgbox('6. Panel Arızalı'))
elseif 306 < x && x < 371 && y > 106
uiwait(msgbox('21. Panel Arızalı'))
end
if 371 < x && x < 434 && y < 106
uiwait(msgbox('7. Panel Arızalı'))
elseif 371 < x && x < 434 && y > 106
uiwait(msgbox('22. Panel Arızalı'))
end
if 434 < x && x < 498 && y < 101
uiwait(msgbox('8. Panel Arızalı'))
elseif 434 < x && x < 498 && y > 101
uiwait(msgbox('23. Panel Arızalı'))
end
if 498 < x && x < 566 && y < 101
uiwait(msgbox('9. Panel Arızalı'))
elseif 498 < x && x < 566 && y > 101
uiwait(msgbox('24. Panel Arızalı'))
end
if 566 < x && x < 629 && y < 94
uiwait(msgbox('10. Panel Arızalı'))
elseif 566 < x && x < 629 && y > 94
uiwait(msgbox('25. Panel Arızalı'))
end
if 629 < x && x < 697 && y < 94
uiwait(msgbox('11. Panel Arızalı'))
elseif 629 < x && x < 697 && y > 94
uiwait(msgbox('26. Panel Arızalı'))
end
if 697 < x && x < 765 && y < 91
uiwait(msgbox('12. Panel Arızalı'))
elseif 697 < x && x < 765 && y > 91
uiwait(msgbox('27. Panel Arızalı'))
end
if 765 < x && x < 831 && y < 89
uiwait(msgbox('13. Panel Arızalı'))
elseif 765 < x && x < 831 && y > 89
uiwait(msgbox('28. Panel Arızalı'))
end
if 848 < x && x < 911 && y < 86
uiwait(msgbox('14. Panel Arızalı'))
elseif 848 < x && x < 911 && y > 86
uiwait(msgbox('29. Panel Arızalı'))
end
if 911 < x && x < 979 && y < 91
uiwait(msgbox('15. Panel Arızalı'))
elseif 911 < x && x < 979 && y > 91
uiwait(msgbox('30. Panel Arızalı'))
end
  1 commentaire
Erkan Karaoglu
Erkan Karaoglu le 25 Juin 2021
@KSSV Can you help with this please ?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by