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 7950283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:13:20+00:00 2026-06-04T02:13:20+00:00

I’m wondering if there are any algorithms out there written in Java currently for

  • 0

I’m wondering if there are any algorithms out there written in Java currently for determining if an image has a low range of different pixel colours contained within it.

I’m trying to detect placeholder images (that typically consist of high percentages of single colours (typically white and grey pixels) as opposed to full colour photos (that consist of a plethora of multiple colours).

If nothing exists, I’ll write something myself (was thinking about sampling an arbitrary pixels in random positions across the image or averaging out all pixel colours contained across the image) and then determining quantities of the different colours I find. There may be a trade off between speed and accuracy depending on the methodology used.

Any advice / pointers / reading material appreciated.

  • 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-04T02:13:21+00:00Added an answer on June 4, 2026 at 2:13 am

    A way to do it would be:

    final BufferedImage image = // your image;
    final Set<Integer> colours = new HashSet<Integer>();
    
    for (int x = 0; x < image.getWidth(); x++) {
      for (int y = 0; y < image.getHeight(); y++) {
        colours.add(image.getRGB(x, y));
      }
    }
    
    // Check your pixels here. In grayscale images the R equals G equals B
    

    You can also use the Java Advanced Imaging(JAI) since it provides a Histogram class:

    package com.datroop.histogram;
    
    import java.awt.image.renderable.ParameterBlock;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.Arrays;
    
    import javax.media.jai.Histogram;
    import javax.media.jai.JAI;
    import javax.media.jai.PlanarImage;
    import javax.media.jai.ROI;
    import javax.media.jai.RenderedOp;
    
    public class HistogramCreator {
    
    private HistogramCreator() {        
    }
    
    public static int[] createHistogram(final PlanarImage image) {
        // set up the histogram
        final int[] bins = { 256 };
        final double[] low = { 0.0D };
        final double[] high = { 256.0D };
    
        Histogram histogram = new Histogram(bins, low, high);
    
        final ParameterBlock pb = new ParameterBlock();
    
        pb.addSource(image);
        pb.add(null);
        pb.add(1);
        pb.add(1);
    
        final RenderedOp op = JAI.create("histogram", pb);
        histogram = (Histogram) op.getProperty("histogram");
    
        // get histogram contents
        final int[] local_array = new int[histogram.getNumBins(0)];
    
        for (int i = 0; i < histogram.getNumBins(0); i++) {
            local_array[i] = histogram.getBinSize(0, i);
        }
    
        return local_array;
    }
    
    public static void main(String[] args) {
        try {
            String filename = "file://localhost/C:/myimage.jpg";
            System.setProperty("com.sun.media.jai.disableMediaLib", "true");
            // Create the histogram
            int[] myHistogram = createHistogram(JAI.create("url", new URL(filename)));
            // Check it out here
            System.out.println(Arrays.toString(myHistogram));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
In my XML file chapters tag has more chapter tag.i need to display chapters

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.