Results 1 to 2 of 2
- 10-07-2012, 04:29 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 60
- Rep Power
- 0
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:
Thus creating a 2d array to hold the 3 bands (RBG) and the frequency of each.Java Code:int [] [] histogram = new int [3][255]
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:
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?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)] ++;
Thanks in advance for any help.
- 10-07-2012, 07:09 PM #2
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
One picture for each texture, or all in one picture
By JG4m3r in forum AndroidReplies: 1Last Post: 05-24-2012, 04:44 PM -
Help with histogram
By Conan in forum New To JavaReplies: 5Last Post: 11-02-2011, 03:51 AM -
need help with name histogram
By cachico12 in forum New To JavaReplies: 1Last Post: 05-09-2011, 08:27 AM -
histogram
By little_man in forum New To JavaReplies: 4Last Post: 11-13-2010, 01:38 AM -
Drawing a picture (applet) using methods
By Jeremy8 in forum New To JavaReplies: 3Last Post: 04-07-2009, 11:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks