Compress DICOM images via Java
Build your own Java apps to compress DICOM files using server-side APIs
How to Compress DICOM Files Using Java
Preparing images for publication involves both creative and technical aspects, including file compression. While high-resolution images are crucial for print or outdoor advertising, they might reduce web performance due to their large file size. The appropriate image compression technique varies depending on the purpose and publishing platform. Large files can slow down loading times, particularly on mobile connections, leading to a poor user experience. Users might abandon a site that takes too long to load and seek a faster alternative. Conversely, excessive image compression can result in blurriness and pixelation, degrading the viewing experience. The right choice of compression algorithms and ratios is essential to strike a balance between file size and image quality. In order to compress DICOM files, we’ll use Aspose.Imaging for Java API which is a feature-rich, powerful and easy to use image manipulation and conversion API for Java platform. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging</artifactId>
<version>version of aspose-imaging API</version>
<classifier>jdk16</classifier>
</dependency>
Steps to Compress DICOM via Java
You need the aspose-imaging-version-jdk16.jar to try the following workflow in your own environment.
- Load DICOM files with Image.load method
- Compress images;
- Save compressed image to disc in the supported by Aspose.Imaging format
System Requirements
Aspose.Imaging for Java is supported on all major operating systems. Just make sure that you have the following prerequisites.
- JDK 1.6 or higher is installed.
Compress DICOM images - Java
import com.aspose.imaging.Image; | |
import com.aspose.imaging.fileformats.dicom.ColorType; | |
import com.aspose.imaging.fileformats.dicom.Compression; | |
import com.aspose.imaging.fileformats.dicom.CompressionType; | |
import com.aspose.imaging.imageoptions.DicomOptions; | |
import com.aspose.imaging.imageoptions.JpegOptions; | |
String templatesFolder = "C:\\WorkDir\\"; | |
String inputFile = templatesFolder + "template.dicom"; | |
String outputFile = templatesFolder + "compressed.dicom"; | |
try (Image image = Image.load(inputFile)) | |
{ | |
DicomOptions options = new DicomOptions(); | |
options.setColorType(ColorType.Grayscale8Bit); // or ColorType.Rgb24Bit for truecolor images | |
Compression compression = new Compression(); | |
compression.setType(CompressionType.Jpeg); | |
compression.setJpeg(new JpegOptions() | |
{{ | |
setQuality(75); | |
}}); | |
options.setCompression(compression); | |
image.save(outputFile, options); | |
} |
About Aspose.Imaging for Java API
Aspose.Imaging API is an image processing solution to create, modify, draw or convert images (photos) within applications. It offers: cross-platform Image processing, including but not limited to conversions between various image formats (including uniform multi-page or multi-frame image processing), modifications such as drawing, working with graphic primitives, transformations (resize, crop, flip&rotate, binarization, grayscale, adjust), advanced image manipulation features (filtering, dithering, masking, deskewing), and memory optimization strategies. It’s a standalone library and does not depend on any software for image operations. One can easily add high-performance image conversion features with native APIs within projects. These are 100% private on-premise APIs and images are processed at your servers.Compress DICOM via Online App
Compress DICOM documents by visiting our Live Demos website The live demo has the following benefits
DICOM What is DICOM File Format
DICOM is the acronym for Digital Imaging and Communications in Medicine and pertains to the field of Medical Informatics. DICOM is the combination of file format definition and a network communications protocol. DICOM uses the .DCM extension. .DCM exist in two different formats i.e. format 1.x and format 2.x. DCM Format 1.x is further available in two versions normal and extended. DICOM is used for the integration of medical imaging devices like printers, servers, scanners etc from various vendors and also contains identification data of each patient for uniqueness. DICOM files can be shared between two parties if they are capable of receiving image data in DICOM format. The communication part of DICOM is application layer protocol and uses TCP/IP to communicate between entities. HTTP and HTTPS protocols are used for the web services of DICOM. Versions supported by web services are 1.0, 1.1, 2 or later.
Read MoreOther Supported Compress Formats
Using Java, one can easily compress different formats including: