MATLAB Answers

How to change a part of the histogram of an image in MATLAB

6 views (last 30 days)
Eman Ezatfar
Eman Ezatfar on 25 Nov 2020
Commented: Image Analyst on 26 Nov 2020
Hi there,
I want to remove some parts(for example in 0-1 scale I want to remove 0.6 up to 0.9) in a RGB image. How can I do that?
I have a picture which background is white but there are noises there( the noises are like you have written something and cleared it with a rubber carelessly, so there are some shades or smth there remained), the written is with blue,black and red pens. I want to write a code that converts colors more than for example 0.8 to 1 so the background would be completely white.
Thanks in advance.

  0 Comments

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 25 Nov 2020
You cannot remove pixels, you can only change them to a different value. What new value do you want to assign pixels that have original values in the range 0.6 to 0.9? Zero? One? What color is the background?
You forgot to attach your image. Please do so if you want more help.

  4 Comments

Show 1 older comment
Image Analyst
Image Analyst on 25 Nov 2020
You could try a different approach to document cleaning. I'm attaching a demo that scans the image and outputs only regions that have strong edges in them.
Otherwise, to do it like you said, by masking your gray scale image in the range 0-1:
mask = grayImage > 0.6 & grayImage < 0.9;
grayImage(mask) = 0; % Or whatever value you want them to take on.
Eman Ezatfar
Eman Ezatfar on 26 Nov 2020
Thanks.
It was usefull, but I do the mask on a grayscale image,can I convert again to RGB ? or do it on RGB ?
Thanks again.
Image Analyst
Image Analyst on 26 Nov 2020
I did the mask on a gray scale image, like you want. Here is an alternative way that will work with either type of image:
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
% Works for gray scale as well as RGB Color images.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by