• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Imaging

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm a beginner in java and i would like to ask how do you operate on images? from what i've searched, it's basically using the BufferedImage class to operate on those images.
i've seen examples such as making filters and all, and i'm quite familiar with some of those. (i've had some little image processing experience using c++)

i would like to know some basics when it comes to handling images. from loading them from a file, to storing them in arrays, and changing pixel values, etc.

thanks.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would use the javax.imageio.ImageIO class to read and write images from files. That would provide you with a BufferedImage object which you can either manipulate directly (through the getRGB and setRGB methods), or you can access its Raster (through the getRaster method), which gives you more ways to manipulate the image.

Note that the values handled by getRGB and setRGB contain all data for a single pixel in one integer: red value, blue value, green value, and alpha value (if the image has one). So if you intend to do work on the individual pixel values, you'll have to extract those values from the integer, transform them as desired, and then put them back together.

This will also help: http://download.oracle.com/javase/tutorial/2d/images/index.html It explains how to perform higher-order image manipulations like drawing geometric shapes.
 
Rex Raleigh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it possible to extract pixel values from an image and store them in a 2d array?

for example, i will load an image and then store it's pixel values to an array. lets say the image size is 100x100 pixels. the first pixel of that image should be at the coordinate (1,1) and thus, stored in an array, say, image[0][0]. from that array, i will try to make some manipulations such as comparing values and such.

i'm really not sure on how to implement this in java since i'm just starting out and re-learning the language.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

is it possible to extract pixel values from an image and store them in a 2d array?



Why do you need to store the pixels in a 2D array? The pixels are already stored in the BufferedImage class. You can access them just like a 2D Array by using the getRGB(x, y) method as suggested earlier. You could always write code to copy them to a 2D array but I don't see the reason for this.
 
Rex Raleigh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the reason i want to do this is i'll try to represent the image as an array of coordinates. i would also try to include only selected parts of the whole picture, thus requiring me to select only certain pixels in the given image.

i'm not that familiar on how to use the BufferedImage class yet, so maybe you could enlighten me on how does it store and operate on the pixels. thanks.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

so maybe you could enlighten me on how does it store and operate on the pixels. thanks.



For the 3rd time is uses the getRGB(...) and setRGB(...) methods.

What don't you understand about that?
 
Rex Raleigh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay i'll take a look at those methods. it would be great if you could provide samples on how to use them so i could understand them better.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you checked the BufferedImage Javadocs? Have you checked getRGB and setRGB, especially their parameters?

Now that you have ( ), how would you get a value at a specific point from an array? And from a BufferedImage?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic