Java DIP Image Pixels - Digital image processing

What are image pixels?

An image includes two dimensional array of pixels. It is known as the value of those pixels that creates an image. While,an image can be color or grayscale.

The BufferedImage class in java is used to manage the images. For this you need to get getRGB() method of the BufferedImage class to grab the value of the pixel.

Getting Pixel Value

Use following syntax to get the value of syntax with that:

Getting RGB Values

The method getRGB() uses the row and column index as a key parameter and returns the exact pixel. To get the color image, it gives back three values which are (Red, Green, Blue). They can be get as follows:

Getting Width and Height of Image

The height and width of the image can done by using the getWidth() and getHeight() methods of the BufferedImage class. Its syntax is given below:

The other methods to that can be supported in the BufferedImage class are described briefly:

Sr.No.

Methods

1

copyData(WritableRaster outRaster)

It computes an arbitrary rectangular region of the BufferedImage and copies it into a specified WritableRaster.

2

getColorModel()

It returns ColorModel of an image.

3

getData()

It returns the image as one large tile.

4

getData(Rectangle rect)

It computes and returns an arbitrary region of the BufferedImage.

5

getGraphics()

This method returns a Graphics2D, but is here for backwards compatibility.

6

getHeight()

It returns the height of the BufferedImage.

7

getMinX()

It returns the minimum x coordinate of this BufferedImage.

8

getMinY()

It returns the minimum y coordinate of this BufferedImage.

9

getRGB(int x, int y)

It returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.

10

getType()

It returns the image type.

Example

Let’s see the use of java BufferedImage class that explain the pixels of an image of size (10 x 10):

Output

After executing the above code, it would print the pixels of the following image:

Original Image.

blackandwhite

Pixels Output

firsthalf

If you scroll down the ouput, the following pattern is seen:

lasthalf

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Digital image processing Topics