Results 1 to 6 of 6
Thread: Counting Pixels
- 11-20-2007, 01:14 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 13
- Rep Power
- 0
Counting Pixels
I am using a buffered image and wish to count the pixels in the image to determine the most prominent colors. I have done some research and think i need to use the ColorModel class. If anyone could tell me how to implement this
and use the ColorModel class it would be greatly appreciated.
Thanks
- 11-20-2007, 03:19 PM #2
the most prominent colors
By this do you mean the colors that occur with the highest frequency, colors with particular qualities, or specific/target colors?
- 11-26-2007, 05:03 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 13
- Rep Power
- 0
I would like to obtain a count of the number of red blue and green colours
- 11-26-2007, 09:34 PM #4
Java Code:import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; public class ColorCount { public static void main(String[] args) throws IOException { String path = pathToImage BufferedImage image = ImageIO.read(new File(path)); int redCount = 0, greenCount = 0, blueCount = 0; int red = Color.red.getRGB(); int green = Color.green.getRGB(); int blue = Color.blue.getRGB(); System.out.printf("red = %d green = %d blue = %d%n", red, green, blue); int w = image.getWidth(); int h = image.getHeight(); for(int y = 0; y < h; y++) { for(int x = 0; x < w; x++) { int pixel = image.getRGB(x, y); if(pixel == red) redCount++; if(pixel == green) greenCount++; if(pixel == blue) blueCount++; } } System.out.printf("redCount = %d greenCount = %d blueCount = %d%n", redCount, greenCount, blueCount); } }
- 11-29-2007, 02:29 PM #5
Member
- Join Date
- Nov 2007
- Posts
- 13
- Rep Power
- 0
Thanks
Thanks for the excellent help your code was very useful. Could you please explain what the following code does especially the role of "d" and "n".
("red = %d green = %d blue = %d%n",
red, green, blue);
- 11-29-2007, 05:51 PM #6
Similar Threads
-
Counting numbers up and down
By radio in forum New To JavaReplies: 4Last Post: 05-06-2011, 03:03 PM -
Modified Pixels
By monkey04 in forum Java 2DReplies: 1Last Post: 03-12-2009, 08:15 AM -
Blurring pixels
By tim in forum New To JavaReplies: 0Last Post: 01-01-2008, 02:06 PM -
Counting Vowels and Constonants
By MattN in forum New To JavaReplies: 3Last Post: 11-20-2007, 05:45 PM -
Deleting certain image pixels..
By Brightside in forum New To JavaReplies: 1Last Post: 05-22-2007, 09:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks