필터 지우기
필터 지우기

how can i select a specific color threshold in a image?

조회 수: 2 (최근 30일)
EM geo
EM geo 2018년 10월 26일
i'm trying to select all the black pixels of some white-black tiff images. I have the code below:
fontSize = 20;
imagefiles=dir('*.TIF');
nfiles=length(imagefiles);
a1=imread('a1.TIF');
[rows1 columns2 numberOfColorBands3] = size(a1);
totalNumberOfPixels1 = (rows1 * columns2)*nfiles;
for i = 1:nfiles
grayImage=imagefiles(i).name;
currentimage=imread(grayImage);
figure;
[rows columns numberOfColorBands] = size(grayImage);
subplot(2, 2, 1);
imshow(currentimage)
title('Original Grayscale Image', 'FontSize', 20);
[pixelCount grayLevels] = imhist(currentimage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
binaryImage = currentimage > 25;
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
numberOfBlackPixels = sum(binaryImage == 0);
numberOfWhitePixels = sum(binaryImage);
percentBlackPixels = 100.0 * numberOfBlackPixels/totalNumberOfPixels1;
percentWhitePixels = 100.0 * numberOfWhitePixels/totalNumberOfPixels1;
end
T = table(numberOfBlackPixels,numberOfWhitePixels,percentBlackPixels,percentWhitePixels);
T(1,:)
filename = 'results_neri_187_1.xlsx';
writetable(T,filename,'Sheet',1,'Range','D1')
With this code i can only select the real black pixels. I need to look at the histogram and select all the black and also some dark gray, but i have to assess it each time. How can i select a threshold of colors in matlab and add it in this code?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Camera Calibration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by