Histogram equalization without histeq (color) (2024)

19 views (last 30 days)

Show older comments

Tito on 18 Nov 2021

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/1589559-histogram-equalization-without-histeq-color

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/1589559-histogram-equalization-without-histeq-color

Commented: DGM on 17 May 2024 at 14:55

Hi guys, I need to do an histogram equalization without using the command "histeq" but I need that in color. All the helps that i've found are in gray scale, I need to get an image equalizated that looks like the one that histeq throws or at least very similar.

I hope you can help me because i've been trying to do it and I always end up with an image with a lot of intensity to the point that it looks way more worst than at the beginning.

Thank you!

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (1)

DGM on 18 Nov 2021

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/1589559-histogram-equalization-without-histeq-color#answer_834379

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/1589559-histogram-equalization-without-histeq-color#answer_834379

Edited: DGM on 18 Nov 2021

Open in MATLAB Online

It all depends on why you can't use histeq(). If you can't use histeq() because you don't have IPT, then MIMT has a drop-in replacement that would work:

nbins = 64;

A = imread('peppers.png');

B = zeros(size(A),class(A));

for c = 1:size(A,3)

% this uses the default 64-bin flat histogram

% you can explicitly specify otherwise

B(:,:,c) = histeq(A(:,:,c),nbins);

end

subplot(2,2,1)

imshow(A)

subplot(2,2,2)

imshow(B)

colors = {'r','g','b'};

subplot(2,2,3)

hold on

for c = 1:size(A,3)

[n,x] = imhist(A(:,:,c),64); % same as MIMT imhistFB()

stem(x,n,colors{c},'marker','none')

end

subplot(2,2,4)

hold on

for c = 1:size(A,3)

[n,x] = imhist(B(:,:,c),64);

stem(x,n,colors{c},'marker','none')

end

Histogram equalization without histeq (color) (3)

If you're avoiding histeq() because this is homework and you're supposed to write it from scratch, then just open histeq() and look at the code and documentation to understand how it works.

Nothing about histogram equalization should imply that the result "looks better". It usually looks awful; the goal is to enforce some desired intensity distribution on the image to facilitate further processing. Maybe you're expecting something more like CLAHE?

A = imread('peppers.png');

B = zeros(size(A),class(A));

for c = 1:size(A,3)

B(:,:,c) = adapthisteq(A(:,:,c));

end

figure;

imshow(B)

Histogram equalization without histeq (color) (4)

You may also elect to do either of these tasks by converting the image to some other model (e.g. LAB) and then doing equalization on the brightness component of the converted image. That may yield more desirable results. If you don't have IPT and need conversion tools, there are alternatives.

nbins = 64;

mode = 'lab'; % pick something

A = imread('peppers.png');

switch mode

case 'hsv'

B = rgb2hsv(A); % not in IPT

%B(:,:,3) = histeq(B(:,:,3),nbins);

B(:,:,3) = adapthisteq(B(:,:,3));

B = im2uint8(hsv2rgb(B));

case 'lab'

B = rgb2lab(A); % MIMT has rgb2lch and others

%B(:,:,1) = histeq(B(:,:,1)/100,nbins)*100;

B(:,:,1) = adapthisteq(B(:,:,1)/100)*100;

B = im2uint8(lab2rgb(B));

end

figure

imshow(B)

Histogram equalization without histeq (color) (5)

2 Comments

Show NoneHide None

Tito on 18 Nov 2021

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1589559-histogram-equalization-without-histeq-color#comment_1840174

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1589559-histogram-equalization-without-histeq-color#comment_1840174

Yes, I'm avoiding histeq() because this is homework and I suppos to write it from scratch and then compare it with the result of run it through histeq(). I tried with the documentation but it only talks about the grayscale case or that's what I understand.

Histogram equalization without histeq (color) (7)

And what I mean by "it looks worse" is that I'm producing this:Histogram equalization without histeq (color) (8)

While histeq() is making this:Histogram equalization without histeq (color) (9)

DGM on 17 May 2024 at 14:55

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1589559-histogram-equalization-without-histeq-color#comment_3164321

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/1589559-histogram-equalization-without-histeq-color#comment_3164321

I don't know why I never responded here, but this sort of result should immediately make you suspect that the output is improperly scaled for its class -- probably because something beforehand was as well. This often occurs if you change working class without rescaling (e.g. using double() instead of im2double()). It can also happen by preallocating the output array implicitly as 'double', and then populating it with (e.g.) uint8-scale data.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

Image Processing and Computer VisionImage Processing ToolboxImage Filtering and EnhancementContrast Adjustment

Find more on Contrast Adjustment in Help Center and File Exchange

Tags

  • image analysis
  • image
  • image processing
  • digital image processing

Products

  • MATLAB

Release

R2021a

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Histogram equalization without histeq (color) (11)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

Histogram equalization without histeq (color) (2024)
Top Articles
Latest Posts
Article information

Author: Jonah Leffler

Last Updated:

Views: 6385

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Jonah Leffler

Birthday: 1997-10-27

Address: 8987 Kieth Ports, Luettgenland, CT 54657-9808

Phone: +2611128251586

Job: Mining Supervisor

Hobby: Worldbuilding, Electronics, Amateur radio, Skiing, Cycling, Jogging, Taxidermy

Introduction: My name is Jonah Leffler, I am a determined, faithful, outstanding, inexpensive, cheerful, determined, smiling person who loves writing and wants to share my knowledge and understanding with you.