MATLAB: How to divide an image at its intensity level??? one part of the histogram is before the mean of image and the other part after the mean of the image

image processingImage Processing Toolboximage segmentation

sir, i want to write a program which separates an image into two parts at its intensity level.one part of the histogram is below the mean of the image and the second part should be after the mean of image and these two parts of histogram of the image should be separately plotted.

Best Answer

threshold = mean2(grayScaleImage); % or whatever intensity you want.
binaryImage = grayScaleImage > threshold;
image1 = grayScaleImage; % Initialize

image1(binaryImage) = 0;
imshow(image1);
image2 = grayScaleImage; % Initialize
image2(~binaryImage) = 0;
imshow(image2);
See attached full blown demo, in blue text below.