Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8498699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:28:27+00:00 2026-06-11T00:28:27+00:00

I have jpegs on a webpage. I would like to perform client-side equalization (contrast

  • 0

I have jpegs on a webpage. I would like to perform client-side equalization (contrast stretching) on these images without browser plugins. I would also accept a solution for histogram equalization.

I currently use a poor approximation with a combination of two CSS filters (-webkit-filter: contrast() brightness()).

I am hoping to be able to accomplish this with something like processing.js or pixastic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:28:28+00:00Added an answer on June 11, 2026 at 12:28 am

    I do not know of a library that contains an efficient histogram equalization method without introducing too much overhead. However, you could lump together your own implementation pretty fast.

    You could start with this very optimized histogram equalization algorithm for 8-bit single channel images taken from js-objectdetect based on back-projection:

    /**
    * Equalizes the histogram of an unsigned 1-channel image with values
    * in range [0, 255]. Corresponds to the equalizeHist OpenCV function.
    *
    * @param {Array} src 1-channel source image
    * @param {Array} [dst] 1-channel destination image. If omitted, the
    * result is written to src (faster)
    * @return {Array} Destination image
    */
    equalizeHistogram = function(src, dst) {
        var srcLength = src.length;
        if (!dst) { dst = src; }
    
        // Compute histogram and histogram sum:
        var hist = new Float32Array(256);
        var sum = 0;
        for (var i = 0; i < srcLength; ++i) {
            ++hist[~~src[i]];
            ++sum;
        }
    
        // Compute integral histogram:
        var prev = hist[0];
        for (var i = 1; i < 256; ++i) {
            prev = hist[i] += prev;
        }
    
        // Equalize image:
        var norm = 255 / sum;
        for (var i = 0; i < srcLength; ++i) {
            dst[i] = hist[~~src[i]] * norm;
        }
        return dst;
    }
    

    You could apply this method to the individual channels of an RGB image independently, but this will produce undesired results. Wikipedia describes a better method:

    “However, if the image is first converted to another color space, Lab
    color space, or HSL/HSV color space in particular, then the algorithm
    can be applied to the luminance or value channel without resulting in
    changes to the hue and saturation of the image.” (Wikipedia)

    You then need an image and a canvas element:

    context = canvas.getContext("2d");
    context.drawImage(image, 0, 0, canvas.width, canvas.height);
    var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
    
    convertRGBAToHSL(imageData.data, hsl);
    equalizeHistogram(hsl[2], hsl[2]);
    convertHSLToRGBA(hsl, rgba);
    

    How to perform RGBA <-> HSL conversation in Javascript is described here.

    Keep in mind that there are 511 possible luminance values for an 8-bit RGB image using the referenced conversion method. Your histogram should then be an array of 511 instead of 256 values. You also would have to make sure that your luminance values are in the correct range, possibly by multiplying with 510 or by modifying the conversion method:

    // r, g, b are in [0..255]
    var max = Math.max(r, g, b), min = Math.min(r, g, b);
    var luminance = max + min;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file that uploads images like jpegs and png onto a
I have a file with multiple jpegs inside. So i would like to split
I have a simple images resizing script that works great for JPEGs, but not
I have a GridView with JPEGs loaded from the network. I'm trying to find
I have a directory full of JPEGs. I want to convert every one of
I have this JPEG image , that opens fine in Picasa, Photoshop, web browser,
I have two images (JPGs). Both are the same width but image2 is shorter
i have a fileinfo array which loads jpegs from a folder. When I add
I have been using ffmpeg to convert a sequence of jpegs to a video
Right, this is the problem I have a container (rar,zip) which contains images png's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.