472,808 Members | 4,096 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,808 software developers and data experts.

jpeg manipulation using java

some of my friends have planned to do A F.R. project using a simple algorithm Eigen Faces usnig Principal Component Analysis( by turk and Petland )

I have used the following code to extract pixel values from a Jpeg image , but it gives me negative values wen i print the pixel values!!
I dont know if I can continue with negative values for further computation like finding the co-variance matrix ...eigen vectors etc... ...
If u know anything please reply.....

Expand|Select|Wrap|Line Numbers
  1. private byte bytes[]=null;
  2. private double doubles[] = null;
  3. private String filename=null;
  4. private int height = 0;
  5. private int width = 0;
  8. private void readImage() throws FileNotFoundException, IOException {
  10. FileInputStream fIn = new FileInputStream(filename);
  11. JPEGImageDecoder jpeg_decode = JPEGCodec.createJPEGDecoder(fIn);
  12. BufferedImage image = jpeg_decode.decodeAsBufferedImage();
  15. width = image.getWidth();
  16. height = image.getHeight();
  18. int[] rgbdata = new int[width * height];
  20. image.getRGB(0,0,width,height,rgbdata,0,width);
  23. bytes = new byte[rgbdata.length];
  24. doubles = new double[rgbdata.length];
  26. for (int i = 0; i < bytes.length; i++) {
  27. bytes = (byte) (rgbdata & 0xFF);
  28. doubles = (double)(rgbdata);
  29. }
Jan 11 '08 #1
3 1956
1,216 Expert 1GB
1. I think you are using old code for reading a jpeg that is not part of the J2SE. You can now use class javax.imageio.ImageIO:

Expand|Select|Wrap|Line Numbers
  1. BufferedImage image = ImageIO.read(url_or_file_etc...);
2. Your code doesn't compile (rgbdata is an array so you can't write "rgbdata & 0xFF"), but I'm guessing your problem is the following. You have some data in a byte. In Java bytes are always signed, so they hold a value in the range [-128,127]. Nevertheless, most programmers use them as though they held a value in the range [0,255]. To obtain this "unsigned" value, do the following:

Expand|Select|Wrap|Line Numbers
  1. byte b = ...
  2. int value = b & 0xff;
I hope the problem doesn't really have to do with your algorithm, which went flying over my head.

If you still have a problem, post a SSCCE: http://mindprod.com/jgloss/sscce.html
Jan 11 '08 #2
Thanks!!!!!!!!!!! i'll be back if i have any more queries
Jan 12 '08 #3
5,000 Expert 4TB
Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

Jan 14 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Derek | last post by:
I wanted to know if anyone had any insight or sample code of creating an AVI file from a directory of JPEG images. I have read the thread that that speaks about creating a MOV file from JPEG images...
by: Patrick | last post by:
Hello all! I am using a BufferedImage object to build an image from scratch. I want it to be a grayscale image with only 8bits of color. I have the color information as a byte, saved in variable...
by: jock | last post by:
Hello, Is it possible to perform basic image manipulation through C? I'd like to upload images through a web interface and resize them so they are limited to a max height/width restriction. ...
by: uli | last post by:
Hi all! I'm searching for a (small) free library for handling JPEG's. Especially I want to load one JPG figure and just rotate it. I have seen the 'Independent JPEG Group' in the Web, but their...
by: David | last post by:
I would like to display a JPEG image from Python on a Windows machine. I Googled 'python jpeg display' and have not found what I am looking for, which is code I can call directly and pass the...
by: zacariaz | last post by:
I dont know, and i dont much like javascript, however, i am told that the only way to do want i want to do, is with javascript, so here goes. zoom and cut is the only features i need. 1. the...
by: Michiel Sikma | last post by:
Hello everybody. I'm currently involved in a site building project in which we're going to use the Google Maps API. The user will be able to browse the site by looking over a really large image,...
by: Robert Larsen | last post by:
Hi group I have some code that saves an image to a file using ImageIO. And it works for all formats except jpeg. A scaled down version follows: public void write(String filename) throws...
by: mndprasad | last post by:
hi all i am doing a project in java where i need to convert 10 jpeg images into a single tiff image..conversion of single jpeg image to single tiff is happening but embedding all the 10 jpeg images...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.