Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to clip histogram?

Subject: How to clip histogram?

From: Learner

Date: 17 Jan, 2012 08:37:08

Message: 1 of 4

hello all,

My problem is something like this:
Suppose we have gray level histogram, from 0 to 255.
Now there are local peaks in histogram, & i want to clip these peaks and redistribute these clipped peaks (i.e. pixels) to other levels.

Suppose i want to half (or one fourth) clip the histogram peaks at level 20-35 and 60-71,, and redistribute it on other levels of same difference i.e. suppose to 40-55 and 210-221.

How to do that?

thanks in advance.

Subject: How to clip histogram?

From: Learner

Date: 17 Jan, 2012 11:28:07

Message: 2 of 4

i tried this for simple clipping, but it is not clipping any thing..

clear all
clc
I = imread('D:/camera.jpg');
grayImage = rgb2gray(I);
[pixel GL]=imhist(grayImage);
if pixel<2500
    pixel = pixel;
end
if pixel>=2500
    pixel=2500;
end
imhist(grayImage)

Subject: How to clip histogram?

From: ImageAnalyst

Date: 18 Jan, 2012 02:29:47

Message: 3 of 4

On Jan 17, 6:28 am, "Learner " <farhan7...@gmail.com> wrote:
> i tried this for simple clipping, but it is not clipping any thing..
>
> clear all
> clc
> I = imread('D:/camera.jpg');
> grayImage = rgb2gray(I);
> [pixel GL]=imhist(grayImage);
> if pixel<2500
>     pixel = pixel;
> end
> if pixel>=2500
>     pixel=2500;
> end
> imhist(grayImage)

-------------------------------------------------------------------------------
Of course nothing happens to the image. You never changed grayImage!
All you changed was the pixel count (distribution) that was returned
from the histogram routine but you never changed the image at all.

If you're going to change the image you have to decide what new gray
levels the "over-represented" gray levels should now take on. For
example, if you have way too many pixels with gray level 123 (let's
say 500,000 of them) and you want to reduce it (say to 100,000 pixels
with gray level 123) then you're going to have to pick 400,000 of
those pixels and assign them to a new gray level(s). The questions to
ask are *which* 400,000 (of the 500,000 pixels total) are you going to
reassign, and what gray level do you want to reassign them to?

But the more relevant question to ask is why do you want to reduce the
histogram peak in the first place? What do you think that will get
you? What are you *really* after?

By the way, you don't need to do this:
if pixel<2500
    pixel = pixel;
end
It does absolutely nothing whatsoever.

ImageAnalyst

Subject: How to clip histogram?

From: Learner

Date: 18 Jan, 2012 06:03:08

Message: 4 of 4

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <2641ffc0-1969-4ec1-ae50-e096ebed48f2@p4g2000vbt.googlegroups.com>...
> On Jan 17, 6:28 am, "Learner " <farhan7...@gmail.com> wrote:
> Of course nothing happens to the image. You never changed grayImage!
> All you changed was the pixel count (distribution) that was returned
> from the histogram routine but you never changed the image at all.
>
> If you're going to change the image you have to decide what new gray
> levels the "over-represented" gray levels should now take on. For
> example, if you have way too many pixels with gray level 123 (let's
> say 500,000 of them) and you want to reduce it (say to 100,000 pixels
> with gray level 123) then you're going to have to pick 400,000 of
> those pixels and assign them to a new gray level(s). The questions to
> ask are *which* 400,000 (of the 500,000 pixels total) are you going to
> reassign, and what gray level do you want to reassign them to?
>
> But the more relevant question to ask is why do you want to reduce the
> histogram peak in the first place? What do you think that will get
> you? What are you *really* after?
>
> By the way, you don't need to do this:
> if pixel<2500
> pixel = pixel;
> end
> It does absolutely nothing whatsoever.
>
> ImageAnalyst

hello sir,
1. Why i want to clip?
Actually by clipping, i want to control the contrast enhancement process.
If we reduce the pixel; the pdf & so the cdf will also change, & then HE method will change its effect as compared to normal application.

2. What gray level do you want to reassign them to?
Yes actually i want to clip the peak to other nearby level.
for eg: let suppose i have this much of pixels:
20,000 at 50th level
22,000 at 55th level
18,000 at 58th level
20,000 at 59th level
& then
10,000 at 121th level
13,000 at 122th level
18,000 at 123th level
16,000 at 124th level

Now I want to clip the pixels of these levels so that at every above defined level, i will get lesser no. of pixels. & then HE is applied to Edited histogram & rebuilt the image back.
-----------------------------------------------------------------------------------
I also want to ask one question:
Is it necessary to redistribute the clipped histogram to other levels? If we don't do this do the no. of pixels will change?
Or we have to clip PDF instead of histogram?

Please help me how to do that.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us