Results 1 to 19 of 19
Thread: reading pixel values from images
- 12-20-2011, 07:47 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 13
- Rep Power
- 0
reading pixel values from images
hi im doing project on extracting a character from images. for that purpose i want to read pixel values from images and store in the 1d array and this array im using for testing purpose. and in using only grayscale images. can anyone provide me the java code to read pixel vlues from images and store it in array.
- 12-20-2011, 12:39 PM #2
Re: reading pixel values from images
Look at the BufferedImage getRGB() method.
- 12-20-2011, 02:07 PM #3
Re: reading pixel values from images
No, this is a forum, not a code mill. If you want someone to write your programs for you, hire a programmer.can anyone provide me the java code
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-22-2011, 05:54 PM #4
Member
- Join Date
- Dec 2011
- Posts
- 13
- Rep Power
- 0
Re: reading pixel values from images
i have written code to read pixel values from images
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
public class ShowImage extends Panel {
BufferedImage image;
public ShowImage() {
try {
System.out.println("Enter image name\n");
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String imageName=bf.readLine();
File input = new File("ab.jpg");
image = ImageIO.read(input);
} catch (IOException ie) {
System.out.println("Error:"+ie.getMessage());
}
}
public void paint(Graphics g) {
g.drawImage( image, 100,100, null);
}
static public void main(String args[]) throws Exception {
JFrame frame = new JFrame("image");
Panel panel = new ShowImage();
frame.getContentPane().add(panel);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
im not geting any error but geting negative values can u tel me the solution for this
- 12-22-2011, 05:56 PM #5
Re: reading pixel values from images
Please show the values you are getting.geting negative values
What statement generates the negative values?
- 12-22-2011, 06:14 PM #6
Member
- Join Date
- Dec 2011
- Posts
- 13
- Rep Power
- 0
Re: reading pixel values from images
im extremally sorry i posted wrong code
this is the correct code
Java Code:import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.JFrame; import java.lang.Exception; import java.awt.Graphics; import java.awt.image.PixelGrabber; import java.awt.image.*; import java.util.*; public class ShowImage3 extends Panel { BufferedImage image; public ShowImage3() { try{ System.out.println("Enter image name\n"); BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); String imageName=bf.readLine(); File input = new File("ab.jpg"); image = ImageIO.read(input); int w = image.getWidth(null); int h = image.getHeight(null); int pixels[] = new int[w*h]; PixelGrabber pg = new PixelGrabber(image,0,0,w,h,pixels,0,w); pg.grabPixels(); int[] data = (int[]) pg.getPixels(); for(int i=0;i<w*h;i++) { System.out.println(""+data[i]); } } catch (Exception ie) { System.out.println("Error:"+ie.getMessage()); } } public void paint(Graphics g) { g.drawImage( image, 100,100, null); } static public void main(String args[]) throws Exception { JFrame frame = new JFrame("image"); Panel panel = new ShowImage3(); frame.getContentPane().add(panel); frame.setSize(500, 500); frame.setVisible(true); } }
and output which im geting is
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1Last edited by Norm; 12-22-2011 at 06:31 PM. Reason: added code tags
- 12-22-2011, 06:30 PM #7
Re: reading pixel values from images
What color do those values represent?
You should look at the values in hexadecimal not in base 10.
-1 is xFFFFFFFFLast edited by Norm; 12-22-2011 at 06:40 PM.
- 12-22-2011, 06:34 PM #8
Member
- Join Date
- Dec 2011
- Posts
- 13
- Rep Power
- 0
Re: reading pixel values from images
color of pixel value is black
- 12-22-2011, 06:43 PM #9
Re: reading pixel values from images
What values do you expect to print out for black?
- 12-22-2011, 06:45 PM #10
Member
- Join Date
- Dec 2011
- Posts
- 13
- Rep Power
- 0
Re: reading pixel values from images
1 if black pixel is present else print zero
- 12-22-2011, 06:49 PM #11
Re: reading pixel values from images
Why do you expect the RGB value for a black pixel to be 1?1 if black pixel is present else print zero
There are 24 bits in the RGB value.
Print out the bits for the Color.black object to see the value of the bits are for black.
- 12-22-2011, 06:51 PM #12
Member
- Join Date
- Dec 2011
- Posts
- 13
- Rep Power
- 0
Re: reading pixel values from images
which part of code i should modify to get proper output
- 12-22-2011, 06:55 PM #13
Re: reading pixel values from images
What output is "proper" output?
The code works for me.
- 12-22-2011, 06:59 PM #14
Member
- Join Date
- Dec 2011
- Posts
- 13
- Rep Power
- 0
Re: reading pixel values from images
what output ur geting same -1 ya something else
- 12-22-2011, 07:03 PM #15
Re: reading pixel values from images
The output will depend on the color of the image. You would get -1 for white.
I get this (in hexadecimal) for a solid colored image: ffff9966 ffff9966 ffff9966 ffff9966 ffff9966 ....
If you want to see the color(sort of orange), use the Color class's constructor to create this color.
- 12-22-2011, 07:10 PM #16
Member
- Join Date
- Dec 2011
- Posts
- 13
- Rep Power
- 0
Re: reading pixel values from images
if im using only grayscale images means it contains only black pixel
what should be the output
what does -1 value represnt
- 12-22-2011, 07:20 PM #17
Re: reading pixel values from images
-1 is 0xFFFFFFFF
You can use the Color class's constructor to create a color object and display it to see what color it is.
For example: new Color(0xFF, 0X15, 0xFF)
The Integer toHexString() method is useful for printing out the RGB values in a more understandable form.Last edited by Norm; 12-22-2011 at 07:24 PM.
- 12-22-2011, 07:31 PM #18
Member
- Join Date
- Dec 2011
- Posts
- 13
- Rep Power
- 0
Re: reading pixel values from images
thanks a lot for ur help
- 12-22-2011, 10:02 PM #19
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
Similar Threads
-
Doubt in assigning pixel values in MemoryImageSource
By atiprashant in forum Java 2DReplies: 8Last Post: 05-18-2011, 03:01 PM -
How to read the pixel values of a jpg binary image
By carindia in forum New To JavaReplies: 2Last Post: 09-17-2010, 06:19 PM -
problem with pixel values of an image
By SreerajSarma in forum New To JavaReplies: 6Last Post: 03-06-2010, 03:47 PM -
compare two images pixel by pixel
By java_bond in forum Advanced JavaReplies: 6Last Post: 03-02-2010, 11:27 AM -
[SOLVED] manipulating the pixel values of an image and constructinf a new image from
By sruthi_2009 in forum AWT / SwingReplies: 14Last Post: 04-10-2009, 08:46 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks