Java Image
For all other classes used for representing graphical images, Java's Image class serves as an abstract superclass. For images in Java, a specific form of object known as a BufferedImage is implemented. Multiple unique image types can be read into a BufferedImage (such as HEIC, BMP, etc.). Plugins are available to expand ImageIO and additional libraries like Apache Imaging and JDeli, albeit not all of these are supported by ImageIO itself.
The complexity of the various image types is concealed in Java itself, and we simply interact with BufferedImage. Java enables image processing and conversions by giving instant access to the picture pixels and color data.
Declaring a Class
The following is the declaration for the class java.awt.Image:
public abstract class Image extends Object
Image Class Fields in Java
Field | Description |
protected float priority acceleration | It gives speeding the image top priority. |
static int SCALE AREA AVERAGING | The area averaging picture scaling algorithm is employed. |
SCALE DEFAULT is a static int. | It employs the standard approach for image scaling. |
SCALE FAST static int | It selects an image-scaling technique that places a larger value on speed of scaling above image smoothness. |
SCALE REPLICATE is a static int. | It employs the ReplicateScaleFilterClass's picture scaling technique. |
SCALE SMOOTH is a static int. | It selects a technique for image scaling that prioritizes image smoothness above scaling speed. |
UnderfinedProperty is a static object. | When retrieving a property that wasn't defined for a certain image, the UndefinedProperty object should always be returned. |
Image Editing
We must use the Graphics object associated with the loaded picture in order to create a form on an image. The characteristics required to carry out simple rendering operations are contained in graphics objects. A class that extends Graphics is called Graphics2D. It gives two-dimensional shapes more control.
To make the shape visible in this situation, we require Graphic2D to increase shape width. By enhancing its stroke property, we accomplish it. After choosing a color, we draw a rectangle 10 pixels away from the image borders.
Graphics2D g = (Graphics2D) myPicture.getGraphics();
g.setStroke(new BasicStroke(3));
g.setColor(Color.BLUE);
g.drawRect(10, 10, myPicture.getWidth() - 20, myPicture.getHeight() - 20);
Putting a Picture Up
We want to display the drawing that we just made on our image. Swing library objects will help us accomplish this. First, a JLabel object is created to serve as a display area for text and/or images.
JLabel picLabel = new JLabel(new ImageIcon(myPicture));
Add our JLabel to JPanel, which we can consider a div>/div> of Java-based GUI, after that.
ImageJ
A Java-based program called ImageJ was developed for working with images. There are a good number of plugins available here. We will only use the API because we wish to handle the processing on our own.
Given that the primary goal of its development was image processing rather than GUI activities, it is a pretty strong library, superior to Swing and AWT. In order to learn image processing and get the results right away, rather than having to tackle the math and optimization issues underlying IP techniques, plugins feature a lot of free-to-use algorithms.
Read and Write: Image Processing in Java
- Java.io.File : Importing the File class is necessary in order to read and write image files. This class represents path names for files and directories in general.
- Java.io.IOException : We make use of the IOException class to deal with issues.
- java.awt.image.BufferedImage : We make a BufferedImage object to store the image using the BufferedImage class. The image that is stored in RAM using this object.
- javax.imgeio.ImageIO : We will import the ImageIO class in order to carry out the read-write operation on an image. Static image reading and writing techniques are available in this class.
The Platform Dependent,
Download the ZIP archive (6MB) and unpack it to get the ImageJ directory in order to install ImageJ on a machine that already has Java installed or to update to the most recent full distribution (which includes macros, plugins, and LUTs). To upgrade to later versions, use the Help>Update ImageJ command.
Mac OS X
Download ImageJ from the Java 8 package (may need to work around Path Randomization). Instructions. Get ImageJ together with Zulu OpenJDK 13.0.6 for Macs with M1 (ARM) processors.
In Linux,
Instructions for downloading ImageJ included with Java 8.
In Windows,
Instructions for downloading ImageJ with 64-bit Java 8.
The Documentation,
The extensive ImageJ User Guide by Tiago Ferreira is accessible as an 8MB PDF file and a ZIP archive. There is a ZIP archive version of the online JavaDoc API documentation as well.
The Source Code,
There are 348 files and 132,000 lines of code in the ImageJ Java source. Online and in zip archives are both available.
Images Examples,
There are 31 downloadable sample images and stacks in the File>Open Samples submenu of ImageJ. Additionally, an 8.2MB zip download including these photographs and more is available.