Image thresholding for different regions of the image

3 visualizaciones (últimos 30 días)
stayfrosty
stayfrosty el 18 de Oct. de 2016
Respondida: Guillaume el 18 de Oct. de 2016
I've applied a global threshold to an image and the results can be seen in this post. How would I apply a different threshold to the bottom half of the image? Applying the same threshold throughout, leaves the bottom half black, which is not what I want. Sorry if this is a silly question.
EDIT: I could apply a threshold to the top half and a different to the bottom half, but the regions aren't exactly perfectly rectangular.
img = imread('result11.png');
img_grey = rgb2gray(img);
% Apply threshold
% md = median(img_grey(img_grey>0));
upper = 230;
lower = 230;
img_grey(img_grey >= upper) = 255;
img_grey(img_grey <= lower) = 0;
% img_grey_bin = img_grey > md;
figure, imshow(img_grey)
BW1 = bwmorph(img_grey, 'clean');
figure, imshow(BW1);

Respuesta aceptada

Guillaume
Guillaume el 18 de Oct. de 2016
Using some sort of adaptive contrast adjustment (such as adapthisteq) or thresholding (such as adaptthresh) should help.
Using the image in your screenshot (which may well be different from your original image, in future attach the raw image), this seems to work reasonably well:
img = rgb2gray(imcrop(imread('threshold example.PNG'), [40 15 926 180])); %load screenshot, crop to input image, convert to greyscale
imshow(imbinarize(img, 'adapt', 'Sensitivity', 0.61));

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by