Got Questions? Get Answers.
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:
Detect Local Minima of a histogram

Subject: Detect Local Minima of a histogram

From: Tessa

Date: 16 Mar, 2010 06:24:07

Message: 1 of 10

I am now working on a histogram of an image, is anyone has any idea
how to detect local maxima and local minima of a histogram? Appreciate
your help. Urgent.

Subject: Detect Local Minima of a histogram

From: Walter Roberson

Date: 16 Mar, 2010 06:49:08

Message: 2 of 10

Tessa wrote:
> I am now working on a histogram of an image, is anyone has any idea
> how to detect local maxima and local minima of a histogram? Appreciate
> your help. Urgent.

Local maxima: the value is greater than both the previous value and the
next value.

Local minima: the value is less than both the previous value and the
next value.


These definitions have a small problem if there are equal adjacent
values: if you have (say) 4 2 2 2 5, then _which_ of the 2's is the
local minima?

I seem to recall that recently John D'Errico mentioned something about a
FEX contribution that took a gradient-based approach to this matter. I
haven't looked at his code, but I would -speculate- that it knows how to
ignore small local minima that are part of a downward trend.

Subject: Detect Local Minima of a histogram

From: Tessa

Date: 16 Mar, 2010 07:11:14

Message: 3 of 10

On Mar 16, 2:49 pm, Walter Roberson <rober...@hushmail.com> wrote:
> Tessa wrote:
> > I am now working on a histogram of an image, is anyone has any idea
> > how to detect local maxima and local minima of a histogram? Appreciate
> > your help. Urgent.
>
> Local maxima: the value is greater than both the previous value and the
> next value.
>
> Local minima: the value is less than both the previous value and the
> next value.
>
> These definitions have a small problem if there are equal adjacent
> values: if you have (say) 4 2 2 2 5, then _which_ of the 2's is the
> local minima?
>
> I seem to recall that recently John D'Errico mentioned something about a
> FEX contribution that took a gradient-based approach to this matter. I
> haven't looked at his code, but I would -speculate- that it knows how to
> ignore small local minima that are part of a downward trend.

Thank you for your sharing.
Let's say if a histogram is ideal, it has some peaks(maxima) and
troughs(minima), however, there are still some noises from the
diagram, if there are only 3 peaks and 3 troughs, but due to noise the
algorithm can detect more than that, which means i need to either
smooth the histogram first, or I need filter those noises to get the
outcome that I want. After I detect them, I need to plot them on the
original histogram as well. Thank you again.

Subject: Detect Local Minima of a histogram

From: ImageAnalyst

Date: 16 Mar, 2010 10:22:57

Message: 4 of 10

Sometimes I've run my histogram through a median filter to smooth it a
bit so that I can try to select a proper threshold. Perhaps you can
try that.

Subject: Detect Local Minima of a histogram

From: Tessa

Date: 17 Mar, 2010 00:35:22

Message: 5 of 10

On Mar 16, 6:22 pm, ImageAnalyst <imageanal...@mailinator.com> wrote:
> Sometimes I've run my histogram through a median filter to smooth it a
> bit so that I can try to select a proper threshold.  Perhaps you can
> try that.

Would you mind to show me how do you do that?

Subject: Detect Local Minima of a histogram

From: ImageAnalyst

Date: 17 Mar, 2010 02:18:50

Message: 6 of 10

On Mar 16, 8:35 pm, Tessa <xiao.ding...@gmail.com> wrote:
> Would you mind to show me how do you do that?
---------------------------------------------------------------------------------------

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear all; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
% Read in standard MATLAB demo image.
grayImage = imread('cameraman.tif');
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image');
[pixelCounts bins] = imhist(grayImage, 256);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
subplot(2, 2, 3);
bar(bins, pixelCounts);
title('Original Histogram');

smoothedHist = medfilt1(pixelCounts, 3)
subplot(2, 2, 4);
bar(bins, smoothedHist);
title('Smoothed Histogram');
msgbox('Done!');

Subject: Detect Local Minima of a histogram

From: Pat Finder

Date: 19 Mar, 2010 06:19:05

Message: 7 of 10

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <69df3a96-9f97-4938-8b7b-c1c6a8b02fea@e1g2000yqh.googlegroups.com>...
> On Mar 16, 8:35 pm, Tessa <xiao.ding...@gmail.com> wrote:
> > Would you mind to show me how do you do that?
> ---------------------------------------------------------------------------------------
> [snip]
>
> [pixelCounts bins] = imhist(grayImage, 256);
>
> [snip]
> smoothedHist = medfilt1(pixelCounts, 3)
> [etc...]

Often in signal processing a Gaussian filter is used.
Any reason why you prefer the median filter?

Subject: Detect Local Minima of a histogram

From: Rune Allnor

Date: 19 Mar, 2010 10:43:52

Message: 8 of 10

On 19 Mar, 07:19, "Pat Finder" <pfin...@netacc.net> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <69df3a96-9f97-4938-8b7b-c1c6a8b02...@e1g2000yqh.googlegroups.com>...
> > On Mar 16, 8:35 pm, Tessa <xiao.ding...@gmail.com> wrote:
> > > Would you mind to show me how do you do that?
> > ---------------------------------------------------------------------------­------------
> > [snip]
>
> > [pixelCounts bins] = imhist(grayImage, 256);
>
> > [snip]
> > smoothedHist = medfilt1(pixelCounts, 3)
> > [etc...]
>
> Often in signal processing a Gaussian filter is used.
> Any reason why you prefer the median filter?

Because this is not about signal processing,
but smoothing a list of non-negative integers.

Rune

Subject: Detect Local Minima of a histogram

From: ImageAnalyst

Date: 19 Mar, 2010 11:58:08

Message: 9 of 10

Pat:
The notable feature of a median filter is that it gets rid of
impulsive noise while allowing true step changes to get through. So
for example, it could remove salt and pepper noise on a dark/light
image of a step edge without blurring out that edge. A Gaussian
filter would average together all pixels in the window (in a weighted
fashion) and blur the edge. Usually you don't want to blur your true
signal, you just want to get rid of the noise, so that's why a
Gaussian filter is not used that much. I'd say a median filter is
used more. There are other filters more sophisticated than Gaussian
filter, such as the bilateral filter (which is still sort of on the
simple side), which are more effective than the Gaussian filter and
are used in preference to the Gaussian filter (at least by those who
know about them).

When I look at a noisy histogram, I usually see the general shape of
the curve but there will often be one bin in between two others that
seems anomalously high or low compared to its neighboring bins. It
looks like impulsive, salt-and-pepper type of noise. I want to fix of
that "bad" bin without changing the true nature of the histogram
curve. So that is why I use a median filter on the histogram array.

You could also use a Gaussian filter, or box filter, to smooth the
array, but that will broaden the "humps" in the histogram more than a
median filter. Of course it all depends on the window sizes you use
for the filters. With any of the box, Gaussian, or median filters, a
larger window size will produce more smoothing/blurring of your
signal. A Gaussian filter would have to be quite broad to get bring
down a big spike bar between two lower bars and thus broaden your
features in your histogram quite a lot, whereas a small median filter
of a 3-bin width will be quite effective at fixing that bin without
broading the other "good" features. One pass with a small median
filter and you instantly and effectively knock out the noise while
keeping your "true" histogram shape.

Does that make sense now?
-ImageAnalyst

Subject: Detect Local Minima of a histogram

From: Twilighter

Date: 15 Jul, 2012 14:40:21

Message: 10 of 10

HI ImageAnalyst

I have a question relating to your answer here, it seems an old post & I thank the person who posted it

I have a program which do some calculations on an image by getting the membership value of pixels using fuzzy logic

this is not the part I'm asking about

the program is calculating this between two peaks after getting the Image histogram

and for the cameraman Image it concidered the two peaks are 20 & 160
from the look at the histogram it seems that it's the value of the two obvious peaks there

what i need to know is how to get the two peaks using matlab ??

the two peaks of a Histogram ? if my interpretation is correct

hope my question is not fuzzy :))

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