Otsu's Threshold Question

조회 수: 2 (최근 30일)
Petrus van Aswegen
Petrus van Aswegen 2021년 9월 4일
댓글: Petrus van Aswegen 2021년 9월 4일
I am attempting to create a classifier which detects the solar panels in a series of images. To create the training data i have been using Otsu's threshold to seperate the blue solar cells from the white grids (see first image below). I have been able to isolate the solar panels from the background, as seen in the second image, and then use the threshold to seperate the classes. I, however, want the blue cells to be highlighted instead of the white grid lines. Does anyone know how to do this? Below is also the code I have been running and the output images at various points.
RGB = imread('1-108.png'); %input image (as seen above)
GT = imread('1-108gt.png'); %original groundtruth of input image which highlights both grid and cell
I = rgb2gray(RGB); %convert RGB to intensity
[row,col] = size(I);
com = uint8(zeros(size(I)));
%when the groundtruth is logic 1, replace this with the corresponding intensity pixel
for r=1:row
for c=1:col
if GT(r,c)==1
com(r,c) = I(r,c);
else
com(r,c) = 0;
end
end
end
figure
imshow(com)
[counts, x] = imhist(com,16);
figure
stem(x,counts)
T = otsuthresh(counts(2:16,:)); %does not consider the first column as this is all the background pixels
BW = imbinarize(com,T);
figure
imshow(BW)

채택된 답변

Matt J
Matt J 2021년 9월 4일
편집: Matt J 2021년 9월 4일
I= double(rgb2gray(imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/729084/1-108.png')));
GT = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/729089/1-108gt.png');
com= uint8((GT==1).*I);
[counts, x] = imhist(com,16);
T = otsuthresh(counts(2:16,:)); %does not consider the first column as this is all the background pixels
BW =GT-imbinarize(com,T);
BW=imclose(BW,ones(3,1));
BW=imfill(BW,'holes');
BW=imopen(BW,ones(5,1));
BW=imopen(BW,ones(1,3));
imshow(BW)
  댓글 수: 1
Petrus van Aswegen
Petrus van Aswegen 2021년 9월 4일
Genius mate, thanks heaps

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image and Video Ground Truth Labeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by