NAVEEN SUMAN
NAVEEN SUMAN

Reputation: 41

image processing

I want to change the value of the pixels in an image, for which i need to store the image as a matrix. How can i perform this job? Please guide.

Upvotes: 4

Views: 288

Answers (3)

venky_ a comrade
venky_ a comrade

Reputation: 1

  • Image is 2d representation of data (pixel info)

  • 2D means x&y directions. In case of image, these directions are generally treated as rows & columns

  • To change the pixel value, we have to get its location in these rows and columns

  • Getting pixel location is like that class teacher addressing the unknown student with his sitting position (ex:2nd bench 3rd person)

  • Like this we have to address the pixel by its rows and column location

Upvotes: 0

code_fish
code_fish

Reputation: 3428

Firstly read the image into a BufferedImage.

BufferedImage image = ImageIO.read(new File("..."));

Then create matrix like structure in the 2D array like this and set RGB:

for(int i = 0; i < image.getWidth(); i++){
   for(int j = 0; j < image.getHeight(); j++){
     image.setRGB(i, j, rgb);  
   } 
}

Upvotes: 0

Bozho
Bozho

Reputation: 597362

BufferedImage image = ImageIO.read(..);
image.setRGB(x, y, rgb);

Check the documentation of BufferedImage

Upvotes: 6

Related Questions