Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
EM geo
EM geo le 26 Oct 2018
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?

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by