MATLAB: Image thresholding for different regions of the image

MATLABmatlab image processing threshold

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);

Best Answer

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));