Results 1 to 2 of 2
  1. #1
    aianta is offline Member
    Join Date
    Apr 2011
    Posts
    63
    Rep Power
    0

    Default Drawing an rbg histogram for a picture

    Hi,
    So I'm currently playing around with some code for a project and I want to be able to get a histogram from a picture that shows me the distributions of color in that picture. Now I have a general idea of how this would work but there are some things that are still fuzzy in my head so I would love if someone could look over my idea here and tell me if it has any merit.

    So I want to begin by filling in my histogram with data. If my histogram is represented by a 2d array then it would look something like this:

    Java Code:
    int [] [] histogram = new int [3][255]
    Thus creating a 2d array to hold the 3 bands (RBG) and the frequency of each.

    So I can now create a 2 for loops to loop through my image and for each pixel increase the frequency count for its specific color like this:

    Java Code:
    for ( int i = 0; i < image.width;i++){
    for (int j = 0 ; j < image.height; j++){
    histogram [0] [image.getSample (i,j,0)] ++;
    histogram [1] [image.getSample (i,j,1)] ++;
    histogram [2] [image.getSample (i,j,2)] ++;
    I now have the data for my histogram correct? So here is where I kinda don't know what to do. How do I draw this data? I am not very familiar with Java2D, from my current understanding, I would have to create a new JPanel and create a method there called paint component. But what should I do from there? Draw 255 lines of varying height really close to each other? Also where can I get this graphics g object that seemingly every method that has anything to do with drawing wants?

    Thanks in advance for any help.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Drawing an rbg histogram for a picture

    Sounds like a bar chart, for which you could use JFreeChart. But if you need to do this yourself, go through Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing) and Trail: 2D Graphics (The Java™ Tutorials) where all your questions will be answered.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 05-24-2012, 04:44 PM
  2. Help with histogram
    By Conan in forum New To Java
    Replies: 5
    Last Post: 11-02-2011, 03:51 AM
  3. need help with name histogram
    By cachico12 in forum New To Java
    Replies: 1
    Last Post: 05-09-2011, 08:27 AM
  4. histogram
    By little_man in forum New To Java
    Replies: 4
    Last Post: 11-13-2010, 01:38 AM
  5. Drawing a picture (applet) using methods
    By Jeremy8 in forum New To Java
    Replies: 3
    Last Post: 04-07-2009, 11:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •