DicomImage

Inheritance: java.lang.Object, com.aspose.imaging.DisposableObject, com.aspose.imaging.DataStreamSupporter, com.aspose.imaging.Image, com.aspose.imaging.RasterImage, com.aspose.imaging.RasterCachedImage, com.aspose.imaging.RasterCachedMultipageImage

All Implemented Interfaces: com.aspose.imaging.IMultipageImageExt

public final class DicomImage extends RasterCachedMultipageImage implements IMultipageImageExt

This Class implements Digital Imaging and Communications in Medicine (DICOM) raster image format support and offers a comprehensive solution for processing DICOM images with precision and flexibility. You can seamlessly manipulate image pages, including operations to get, add, or remove pages, and control the default and active pages. With capabilities to work with alpha channels, embed XMP metadata, resize, rotate, crop, binarize, adjust, apply filters, and convert to other raster formats. This API empowers developers to handle DICOM images effectively while meeting diverse application requirements in medical imaging contexts.

Constructors

ConstructorDescription
DicomImage(DicomOptions dicomImage, int width, int height)Initialize a fresh instance of the DicomImage class effortlessly with this constructor, utilizing dicomOptions parameters.
DicomImage(InputStream stream, LoadOptions loadOptions)Initiate a new instance of the DicomImage class smoothly by employing a stream and loadOptions parameters in this constructor.
DicomImage(InputStream stream)Create a new instance of the DicomImage class by utilizing a stream parameter in this constructor.

Methods

MethodDescription
getPageCount()Retrieve the total page count of the image with this intuitive property.
getPages()Access the pages of the image with this intuitive property.
getFileInfo()Retrieve valuable header information from the DICOM file effortlessly with this intuitive property.
getDicomPages()Access the pages of the image with this intuitive property.
getActivePage()Access to the active page of the image with this intuitive property.
setActivePage(DicomPage value)Manage the active page of the image with this intuitive property.
getActivePageIndex()Retrieve the index of the active page effortlessly with this intuitive property.
getFileFormat()Retrieve the file format value effortlessly with this intuitive property.
hasAlpha()Retrieve whether the image has an alpha channel effortlessly with this intuitive property.
getPageExportingAction()Manage the page exporting action with this intuitive property.
setPageExportingAction(PageExportingAction value)Manage the page exporting action with this intuitive property.
addPage(RasterImage page)Expand your image collection by adding a new page with this intuitive method.
saveAll(String filePath, ImageOptionsBase options)Preserve the object’s data by saving it to the designated file (indexer + filename) location along with specified file format and options.
setResolution(double dpiX, double dpiY)Adjust the resolution of this RasterImage with precision using this straightforward method.
resizeProportional(int newWidth, int newHeight, int resizeType)Resize the image while maintaining its aspect ratio with this convenient method.
addPage()Append a new page to the end of the image’s page list with this straightforward method.
insertPage(int pageIndex)Insert a new page into the image’s page list at a specified index with this intuitive method.
removePage(int pageIndex)Eliminate the page at the specified index from the page list with this convenient method.
rotate(float angle, boolean resizeProportionally, Color backgroundColor)Rotate the image around its center with this convenient method.
resize(int newWidth, int newHeight, int resizeType)Adjust the size of the image with this straightforward method.
resizeWidthProportionally(int newWidth, int resizeType)Adjust the width of the image while maintaining its aspect ratio with this convenient method.
resizeHeightProportionally(int newHeight, int resizeType)Adjust the height of the image while maintaining its aspect ratio with this user-friendly method.
rotateFlip(int rotateFlipType)Easily manipulate the active frame by rotating, flipping, or performing both actions simultaneously with this straightforward method.
dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)Enhance the current image by applying dithering effects with this straightforward method.
crop(Rectangle rectangle)Crop the image to remove unwanted areas and focus on essential content with this simple method.
crop(int leftShift, int rightShift, int topShift, int bottomShift)Adjust the cropping area of the image by applying shifts with this versatile method.
binarizeFixed(byte threshold)Easily convert the image into a binary format using a predefined threshold with this straightforward method.
binarizeOtsu()Apply Otsu thresholding to binarize the image, automatically determining the optimal threshold value based on the image’s histogram.
binarizeBradley(double brightnessDifference, int windowSize)Binarize images with Bradley’s adaptive thresholding algorithm, leveraging integral image thresholding for improved performance.
grayscale()Easily transform images into their grayscale representation, simplifying visual analysis and processing tasks.
adjustGamma(float gamma)Enhance image quality and adjust it with gamma correction, a powerful technique for fine-tuning visual appearance.
adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)Achieve precise color adjustments by applying gamma correction independently to the red, green, and blue components of an image.
adjustBrightness(int brightness)Enhance image luminance with the adjustment of brightness, a parameterized method that allows developers to finely tune the luminosity of images.
adjustContrast(float contrast)Enhance Image contrast with this user-friendly method, which adjusts the disparity between light and dark areas.
filter(Rectangle rectangle, FilterOptionsBase options)Effortlessly enhance specific areas of your image by applying filters to designated rectangles.
resize(int newWidth, int newHeight, ImageResizeSettings settings)Adjust the size of your image with this simple resizing method.
cacheData()This method efficiently caches data, optimizing performance and ensuring swift access when needed.

Example: This example demonstrates the loading and exporting of dicom file.


String dir = "c:\\temp\\";

// Load an image
com.aspose.imaging.fileformats.dicom.DicomImage image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load("sample.dicom");
try {
    image.adjustBrightness(50);
    image.save(dir + "sample.dicom.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

Example: Create a multi-page Dicom image.

        
try (DicomOptions dicomOptions = new DicomOptions())
{
    dicomOptions.setSource(new StreamSource());
    try (DicomImage image = (DicomImage) Image.create(
            dicomOptions,
            100,
            100))
    {
        // Draw something using vector graphics
        Graphics graphics = new Graphics(image);
        graphics.fillRectangle(new SolidBrush(Color.getBlueViolet()), image.getBounds());
        graphics.fillRectangle(new SolidBrush(Color.getAqua()), 10, 20, 50, 20);
        graphics.fillEllipse(new SolidBrush(Color.getOrange()), 30, 50, 70, 30);

        // Save the pixels of the drawn image. They are now on the first page of the Dicom image.
        int[] pixels = image.loadArgb32Pixels(image.getBounds());

        // Add a few pages after, making them darker
        for (int i = 1; i < 5; i++)
        {
            DicomPage page = image.addPage();
            page.saveArgb32Pixels(page.getBounds(), pixels);
            page.adjustBrightness(i * 30);
        }

        // Add a few pages in front of the main page, making them brighter
        for (int i = 1; i < 5; i++)
        {
            DicomPage page = image.insertPage(0);
            page.saveArgb32Pixels(page.getBounds(), pixels);
            page.adjustBrightness(-i * 30);
        }

        // Save the created multi-page image to the output file
        image.save("MultiPage.dcm");
    }
}

Example: Use JPEG compression in DICOM image.

try (Image inputImage = Image.load("original.jpg"))
{
    DicomOptions options = new DicomOptions();
    options.setColorType(ColorType.Rgb24Bit);

    Compression compression = new Compression();
    compression.setType(CompressionType.Jpeg);
    JpegOptions jpegOptions = new JpegOptions();
    jpegOptions.setCompressionType(JpegCompressionMode.Baseline);
    jpegOptions.setSampleRoundingMode(SampleRoundingMode.Truncate);
    jpegOptions.setQuality(50);
    compression.setJpeg(jpegOptions);

    options.setCompression(compression);

    inputImage.save("original_JPEG.dcm", options);
}

Example: Use JPEG 2000 compression in DICOM image.

try (Image inputImage = Image.load("original.jpg"))
{
    DicomOptions options = new DicomOptions();
    options.setColorType(ColorType.Rgb24Bit);

    Compression compression = new Compression();
    compression.setType(CompressionType.Jpeg2000);
    Jpeg2000Options jpegOptions = new Jpeg2000Options();
    jpegOptions.setCodec(Jpeg2000Codec.Jp2);
    jpegOptions.setIrreversible(false);
    compression.setJpeg2000(jpegOptions);

    options.setCompression(compression);

    inputImage.save("original_JPEG2000.dcm", options);
}

Example: Use RLE compression in DICOM image.

try (Image inputImage = Image.load("original.jpg"))
{
    DicomOptions options = new DicomOptions();
    options.setColorType(ColorType.Rgb24Bit);

    Compression compression = new Compression();
    compression.setType(CompressionType.Rle);
    options.setCompression(compression);

    inputImage.save("original_RLE.dcm", options);
}

Example: Change Color Type in DICOM compression.

try (Image inputImage = Image.load("original.jpg"))
{
    DicomOptions options = new DicomOptions();
    options.setColorType(ColorType.Grayscale8Bit);

    inputImage.save("original_8Bit.dcm", options);
}

DicomImage(DicomOptions dicomImage, int width, int height)

public DicomImage(DicomOptions dicomImage, int width, int height)

Initialize a fresh instance of the DicomImage class effortlessly with this constructor, utilizing dicomOptions parameters. Perfect for developers looking to dive into DicomImage objects swiftly and efficiently in their projects.

Parameters:

ParameterTypeDescription
dicomImageDicomOptionsThe dicom options (ignoring now).
widthintThe width.
heightintThe height.

DicomImage(InputStream stream, LoadOptions loadOptions)

public DicomImage(InputStream stream, LoadOptions loadOptions)

Initiate a new instance of the DicomImage class smoothly by employing a stream and loadOptions parameters in this constructor. Ideal for developers eager to start working with DicomImage objects promptly and effectively in their projects.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream.
loadOptionsLoadOptionsThe load options.

DicomImage(InputStream stream)

public DicomImage(InputStream stream)

Create a new instance of the DicomImage class by utilizing a stream parameter in this constructor. Perfect for developers seeking a streamlined way to initialize DicomImage objects from existing data streams in their projects.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream.

getPageCount()

public int getPageCount()

Retrieve the total page count of the image with this intuitive property. Ideal for developers seeking quick access to the number of pages within an image, ensuring efficient navigation and management.

Returns: int - the page count.

getPages()

public Image[] getPages()

Access the pages of the image with this intuitive property. Ideal for developers seeking to interact with individual pages within the image, ensuring seamless navigation and manipulation.

Returns: com.aspose.imaging.Image[] - the pages.

getFileInfo()

public DicomImageInfo getFileInfo()

Retrieve valuable header information from the DICOM file effortlessly with this intuitive property. Ideal for developers seeking quick access to essential details encapsulated within the DICOM file, ensuring efficient data extraction and analysis.

Returns: DicomImageInfo - a value, which contains info header the DICOM file

getDicomPages()

public DicomPage[] getDicomPages()

Access the pages of the image with this intuitive property. Ideal for developers seeking to interact with individual pages within the image, ensuring seamless navigation and manipulation.

Returns: com.aspose.imaging.fileformats.dicom.DicomPage[] - the pages.

getActivePage()

public DicomPage getActivePage()

Access to the active page of the image with this intuitive property. Ideal for developers seeking to dynamically switch between pages within multi-page images, ensuring efficient navigation and processing.

Returns: DicomPage - the active page.

setActivePage(DicomPage value)

public void setActivePage(DicomPage value)

Manage the active page of the image with this intuitive property. Ideal for developers seeking to dynamically switch between pages within multi-page images, ensuring efficient navigation and processing.

Parameters:

ParameterTypeDescription
valueDicomPagethe active page.

getActivePageIndex()

public int getActivePageIndex()

Retrieve the index of the active page effortlessly with this intuitive property. Ideal for developers seeking quick access to the current page index within multi-page images, ensuring efficient navigation and processing.

Returns: int - the index active page.

getFileFormat()

public long getFileFormat()

Retrieve the file format value effortlessly with this intuitive property. Ideal for developers seeking quick access to the format of the image file, ensuring efficient handling and processing based on the file type.

Returns: long - a value of file format FileFormat.

hasAlpha()

public boolean hasAlpha()

Retrieve whether the image has an alpha channel effortlessly with this intuitive property. Ideal for developers seeking to determine if the image contains transparency information, ensuring precise handling of alpha channel data in image processing tasks.

Returns: boolean - true if image has alpha channel.

getPageExportingAction()

public PageExportingAction getPageExportingAction()

Manage the page exporting action with this intuitive property. Ideal for developers seeking to control the export behavior of image pages, ensuring seamless integration and customization in various image processing workflows.

Returns: PageExportingAction - the page exporting action.

setPageExportingAction(PageExportingAction value)

public void setPageExportingAction(PageExportingAction value)

Manage the page exporting action with this intuitive property. Ideal for developers seeking to control the export behavior of image pages, ensuring seamless integration and customization in various image processing workflows. Please note that setting this method will automatically release page resources after it is executed. It will be executed just before each page is saved.

Parameters:

ParameterTypeDescription
valuePageExportingActionthe page exporting action.

addPage(RasterImage page)

public void addPage(RasterImage page)

Expand your image collection by adding a new page with this intuitive method. Ideal for developers seeking to dynamically append pages to multi-page images, ensuring seamless expansion and organization of image content.

Parameters:

ParameterTypeDescription
pageRasterImageThe page to add.

saveAll(String filePath, ImageOptionsBase options)

public void saveAll(String filePath, ImageOptionsBase options)

Preserve the object’s data by saving it to the designated file (indexer + filename) location along with specified file format and options. Ideal for developers seeking to securely store data in various formats while maintaining flexibility and control over saving parameters.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe file path.
optionsImageOptionsBaseThe options.

setResolution(double dpiX, double dpiY)

public void setResolution(double dpiX, double dpiY)

Adjust the resolution of this RasterImage with precision using this straightforward method. Ideal for developers looking to tailor image resolution to specific requirements, ensuring optimal display quality and file size management.

Parameters:

ParameterTypeDescription
dpiXdoubleThe horizontal resolution, in dots per inch, of the RasterImage.
dpiYdoubleThe vertical resolution, in dots per inch, of the RasterImage.

resizeProportional(int newWidth, int newHeight, int resizeType)

public void resizeProportional(int newWidth, int newHeight, int resizeType)

Resize the image while maintaining its aspect ratio with this convenient method. Ideal for developers seeking to adjust the image dimensions proportionally, ensuring consistency and preserving the original content’s proportions. The proportional resize will resize each frame according to the ratio of newWidth/width and newHeight/height.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
newHeightintThe new height.
resizeTypeintThe resize type.

addPage()

public DicomPage addPage()

Append a new page to the end of the image’s page list with this straightforward method. Ideal for developers seeking to dynamically expand multi-page images, ensuring seamless integration and organization of image content.

Returns: DicomPage - The newly created DicomPage.

insertPage(int pageIndex)

public DicomPage insertPage(int pageIndex)

Insert a new page into the image’s page list at a specified index with this intuitive method. Ideal for developers seeking precise control over the arrangement of pages in multi-page images, ensuring seamless organization and customization of image content.

Parameters:

ParameterTypeDescription
pageIndexintIndex of the page.

Returns: DicomPage - The newly created DicomPage.

Example: Create a multi-page Dicom image.

        
try (DicomOptions dicomOptions = new DicomOptions())
{
    dicomOptions.setSource(new StreamSource());
    try (DicomImage image = (DicomImage) Image.create(
            dicomOptions,
            100,
            100))
    {
        // Draw something using vector graphics
        Graphics graphics = new Graphics(image);
        graphics.fillRectangle(new SolidBrush(Color.getBlueViolet()), image.getBounds());
        graphics.fillRectangle(new SolidBrush(Color.getAqua()), 10, 20, 50, 20);
        graphics.fillEllipse(new SolidBrush(Color.getOrange()), 30, 50, 70, 30);

        // Save the pixels of the drawn image. They are now on the first page of the Dicom image.
        int[] pixels = image.loadArgb32Pixels(image.getBounds());

        // Add a few pages after, making them darker
        for (int i = 1; i < 5; i++)
        {
            DicomPage page = image.addPage();
            page.saveArgb32Pixels(page.getBounds(), pixels);
            page.adjustBrightness(i * 30);
        }

        // Add a few pages in front of the main page, making them brighter
        for (int i = 1; i < 5; i++)
        {
            DicomPage page = image.insertPage(0);
            page.saveArgb32Pixels(page.getBounds(), pixels);
            page.adjustBrightness(-i * 30);
        }

        // Save the created multi-page image to the output file
        image.save("MultiPage.dcm");
    }
}

removePage(int pageIndex)

public void removePage(int pageIndex)

Eliminate the page at the specified index from the page list with this convenient method. Ideal for developers seeking precise control over the management of multi-page images, ensuring seamless organization and customization of image content.

Parameters:

ParameterTypeDescription
pageIndexintIndex of the page.

rotate(float angle, boolean resizeProportionally, Color backgroundColor)

public void rotate(float angle, boolean resizeProportionally, Color backgroundColor)

Rotate the image around its center with this convenient method. Ideal for developers seeking to adjust image orientation dynamically, ensuring optimal presentation and alignment within their applications.

Parameters:

ParameterTypeDescription
anglefloatThe rotating angle in degrees. Positive values will rotate clockwise.
resizeProportionallybooleanif set to true you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only `` image contents are rotated.
backgroundColorColorColor of the background.

Example: This example shows how to rotate all pages of a DICOM image and save them all to a multi-frame TIFF image.

String dir = "c:\\temp\\";

// Load a DICOM image from a file stream.
java.io.FileInputStream stream = new java.io.FileInputStream(dir + "multiframe.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = new com.aspose.imaging.fileformats.dicom.DicomImage(stream);
    try {
        // Rotate the image around the center by 60 degrees clockwise.
        // Use gray as the background color.
        dicomImage.rotate(60, true, com.aspose.imaging.Color.getGray());

        com.aspose.imaging.imageoptions.TiffOptions createOptions = new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default);
        createOptions.setCompression(com.aspose.imaging.fileformats.tiff.enums.TiffCompressions.Deflate);

        // Note that if the image is colorful, it will be automatically converted to the grayscale format according to the options below
        createOptions.setPhotometric(com.aspose.imaging.fileformats.tiff.enums.TiffPhotometrics.MinIsBlack);
        createOptions.setBitsPerSample(new int[]{8});

        // Create an array of TIFF frames.
        // The number of the frames is equal to the number of the DJVU pages.
        com.aspose.imaging.fileformats.dicom.DicomPage[] pages = dicomImage.getDicomPages();
        com.aspose.imaging.fileformats.tiff.TiffFrame[] tiffFrames = new com.aspose.imaging.fileformats.tiff.TiffFrame[pages.length];

        // Save each page as an individual TIFF frame.
        for (com.aspose.imaging.fileformats.dicom.DicomPage dicomPage : pages) {
            // Create a TIFF frame based on the DICOM page.
            tiffFrames[dicomPage.getIndex()] = new com.aspose.imaging.fileformats.tiff.TiffFrame(dicomPage, createOptions);
        }

        // Compose a TIFF image from the frames.
        com.aspose.imaging.fileformats.tiff.TiffImage tiffImage = new com.aspose.imaging.fileformats.tiff.TiffImage(tiffFrames);
        try {
            // Save to a file.
            tiffImage.save(dir + "multiframe.tif");
        } finally {
            tiffImage.dispose();
        }
    } finally {
        dicomImage.dispose();
    }
} finally {
    stream.close();
}

resize(int newWidth, int newHeight, int resizeType)

public void resize(int newWidth, int newHeight, int resizeType)

Adjust the size of the image with this straightforward method. Ideal for developers looking to dynamically resize images, ensuring they fit seamlessly into various contexts and layouts within their applications.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
newHeightintThe new height.
resizeTypeintThe resize type.

Example: This example loads a DICOM image and resizes it using various resizing methods.

String dir = "c:\\temp\\";

com.aspose.imaging.fileformats.dicom.DicomImage image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale up by 2 times using Nearest Neighbour resampling.
    image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // Save to PNG with default options.
    image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale down by 2 times using Nearest Neighbour resampling.
    image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // Save to PNG with default options.
    image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale up by 2 times using Bilinear resampling.
    image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);

    // Save to PNG with default options.
    image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale down by 2 times using Bilinear resampling.
    image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);

    // Save to PNG with default options.
    image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

resizeWidthProportionally(int newWidth, int resizeType)

public void resizeWidthProportionally(int newWidth, int resizeType)

Adjust the width of the image while maintaining its aspect ratio with this convenient method. Ideal for developers seeking to resize images proportionally, ensuring consistent and visually appealing results across different display environment.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
resizeTypeintType of the resize.

Example: This example loads a DICOM image and resizes it proportionally using various resizing methods. This example loads a DICOM image and resizes it proportionally using various resizing methods. Only the width is specified, the height is calculated automatically.

String dir = "c:\\temp\\";

com.aspose.imaging.fileformats.dicom.DicomImage image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale up by 2 times using Nearest Neighbour resampling.
    image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // Save to PNG with the default options.
    image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale down by 2 times using Nearest Neighbour resampling.
    image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // Save to PNG with the default options.
    image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale up by 2 times using Bilinear resampling.
    image.resizeWidthProportionally(image.getWidth() * 2, com.aspose.imaging.ResizeType.BilinearResample);

    // Save to PNG with the default options.
    image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale down by 2 times using Bilinear resampling.
    image.resizeWidthProportionally(image.getWidth() / 2, com.aspose.imaging.ResizeType.BilinearResample);

    // Save to PNG with the default options.
    image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

resizeHeightProportionally(int newHeight, int resizeType)

public void resizeHeightProportionally(int newHeight, int resizeType)

Adjust the height of the image while maintaining its aspect ratio with this user-friendly method. Perfect for developers seeking to dynamically resize images while preserving their proportions, ensuring optimal display and usability in their applications.

Parameters:

ParameterTypeDescription
newHeightintThe new height.
resizeTypeintType of the resize.

Example: This example loads a DICOM image and resizes it proportionally using various resizing methods. This example loads a DICOM image and resizes it proportionally using various resizing methods. Only the height is specified, the width is calculated automatically.

String dir = "c:\\temp\\";

com.aspose.imaging.fileformats.dicom.DicomImage image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale up by 2 times using Nearest Neighbour resampling.
    image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // Save to PNG with the default options.
    image.save(dir + "upsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale down by 2 times using Nearest Neighbour resampling.
    image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);

    // Save to PNG with the default options.
    image.save(dir + "downsample.nearestneighbour.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale up by 2 times using Bilinear resampling.
    image.resizeHeightProportionally(image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);

    // Save to PNG with the default options.
    image.save(dir + "upsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // Scale down by 2 times using Bilinear resampling.
    image.resizeHeightProportionally(image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);

    // Save to PNG with the default options.
    image.save(dir + "downsample.bilinear.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

rotateFlip(int rotateFlipType)

public void rotateFlip(int rotateFlipType)

Easily manipulate the active frame by rotating, flipping, or performing both actions simultaneously with this straightforward method. Ideal for developers who need to dynamically adjust the orientation of specific frames within their image sequences, ensuring optimal presentation and alignment.

Parameters:

ParameterTypeDescription
rotateFlipTypeintThe rotating flip type.

Example: This example loads a DICOM image, rotates it by 90 degrees clockwise and optionally flips the image horizontally and(or) vertically.

String dir = "c:\\temp\\";

int[] rotateFlipTypes = new int[]
        {
                com.aspose.imaging.RotateFlipType.Rotate90FlipNone,
                com.aspose.imaging.RotateFlipType.Rotate90FlipX,
                com.aspose.imaging.RotateFlipType.Rotate90FlipXY,
                com.aspose.imaging.RotateFlipType.Rotate90FlipY,
        };

for (int rotateFlipType : rotateFlipTypes) {
    // Rotate, flip and save to the output file.
    com.aspose.imaging.fileformats.dicom.DicomImage image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
    try {
        image.rotateFlip(rotateFlipType);
        image.save(dir + "sample." + rotateFlipType + ".png", new com.aspose.imaging.imageoptions.PngOptions());
    } finally {
        image.dispose();
    }
}

dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)

public void dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)

Enhance the current image by applying dithering effects with this straightforward method. Perfect for developers aiming to add texture and depth to images, improving their visual quality and overall appeal.

Parameters:

ParameterTypeDescription
ditheringMethodintThe dithering method.
bitsCountintThe final bits count for dithering.
customPaletteIColorPaletteThe custom palette for dithering.

Example: The following example loads a DICOM image and performs threshold and floyd dithering using different palette depth.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Perform threshold dithering using 4-bit color palette which contains 16 colors.
    // The more bits specified the higher quality and the bigger size of the output image.
    // Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
    dicomImage.dither(com.aspose.imaging.DitheringMethod.ThresholdDithering, 4, null);

    dicomImage.save(dir + "sample.ThresholdDithering4.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.dicom");
{
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Perform floyd dithering using 1-bit color palette which contains only 2 colors - black and white.
    // The more bits specified the higher quality and the bigger size of the output image.
    // Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
    dicomImage.dither(com.aspose.imaging.DitheringMethod.FloydSteinbergDithering, 1, null);

    dicomImage.save(dir + "sample.FloydSteinbergDithering1.png", new com.aspose.imaging.imageoptions.PngOptions());
}

crop(Rectangle rectangle)

public void crop(Rectangle rectangle)

Crop the image to remove unwanted areas and focus on essential content with this simple method. Ideal for developers seeking to customize the visual composition of images, ensuring they convey the desired message effectively.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle.

Example: The following example crops a DICOM image. The following example crops a DICOM image. The cropping area is be specified via Aspose.Imaging.Rectangle.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Crop the image. The cropping area is the rectangular central area of the image.
    com.aspose.imaging.Rectangle area =
            new com.aspose.imaging.Rectangle(
                    dicomImage.getWidth() / 4, dicomImage.getHeight() / 4, dicomImage.getWidth() / 2, dicomImage.getHeight() / 2);
    dicomImage.crop(area);

    // Save the cropped image to PNG
    dicomImage.save(dir + "sample.Crop.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

crop(int leftShift, int rightShift, int topShift, int bottomShift)

public void crop(int leftShift, int rightShift, int topShift, int bottomShift)

Adjust the cropping area of the image by applying shifts with this versatile method. Perfect for developers who need precise control over the cropping process, ensuring that important details are retained while eliminating unnecessary elements.

Parameters:

ParameterTypeDescription
leftShiftintThe left shift.
rightShiftintThe right shift.
topShiftintThe top shift.
bottomShiftintThe bottom shift.

Example: The following example crops a DICOM image. The following example crops a DICOM image. The cropping area is specified via Left, Top, Right, Bottom margins.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Crop again. Set a margin of 10% of the image size.
    int horizontalMargin = dicomImage.getWidth() / 10;
    int verticalMargin = dicomImage.getHeight() / 10;
    dicomImage.crop(horizontalMargin, horizontalMargin, verticalMargin, verticalMargin);

    // Save the cropped image to PNG.
    dicomImage.save(dir + "sample.Crop.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

binarizeFixed(byte threshold)

public void binarizeFixed(byte threshold)

Easily convert the image into a binary format using a predefined threshold with this straightforward method. Ideal for developers looking to simplify image processing tasks by segmenting the image into foreground and background components based on specified intensity levels.

Parameters:

ParameterTypeDescription
thresholdbyteThreshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.

Example: The following example binarizes a DICOM image with the predefined threshold. The following example binarizes a DICOM image with the predefined threshold. Binarized images contain only 2 colors - black and white.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Binarize the image with a threshold value of 127.
    // If a corresponding gray value of a pixel is greater than 127, a value of 255 will be assigned to it, 0 otherwise.
    dicomImage.binarizeFixed((byte) 127);
    dicomImage.save(dir + "sample.BinarizeFixed.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

binarizeOtsu()

public void binarizeOtsu()

Apply Otsu thresholding to binarize the image, automatically determining the optimal threshold value based on the image’s histogram. Perfect for developers seeking a reliable method to segment images into foreground and background regions with minimal manual intervention.

Example: The following example binarizes a DICOM image with Otsu thresholding. The following example binarizes a DICOM image with Otsu thresholding. Binarized images contain only 2 colors - black and white.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Binarize the image with Otsu thresholding.
    dicomImage.binarizeOtsu();
    dicomImage.save(dir + "sample.BinarizeOtsu.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

binarizeBradley(double brightnessDifference, int windowSize)

public void binarizeBradley(double brightnessDifference, int windowSize)

Binarize images with Bradley’s adaptive thresholding algorithm, leveraging integral image thresholding for improved performance. Ideal for developers looking to automatically segment images based on local variations in brightness, ensuring accurate object detection and extraction in varying lighting conditions.

Parameters:

ParameterTypeDescription
brightnessDifferencedoubleThe brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
windowSizeintThe size of s x s window of pixels centered around this pixel

Example: The following example binarizes a DICOM image with Bradley’s adaptive thresholding algorithm with the specified window size. The following example binarizes a DICOM image with Bradley’s adaptive thresholding algorithm with the specified window size. Binarized images contain only 2 colors - black and white.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Binarize the image with a brightness difference of 5. The brightness is a difference between a pixel and the average of an 10 x 10 window of pixels centered around this pixel.
    dicomImage.binarizeBradley(5, 10);
    dicomImage.save(dir + "sample.BinarizeBradley5_10x10.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

grayscale()

public void grayscale()

Easily transform images into their grayscale representation, simplifying visual analysis and processing tasks. Perfect for developers seeking to enhance image clarity, reduce complexity, and facilitate efficient grayscale-based algorithms for diverse applications.

Example: The following example transforms a colored DICOM image to its grayscale representation. The following example transforms a colored DICOM image to its grayscale representation. Grayscale images are composed exclusively of shades of gray and carry only intensity information.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    dicomImage.grayscale();
    dicomImage.save(dir + "sample.Grayscale.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

adjustGamma(float gamma)

public void adjustGamma(float gamma)

Enhance image quality and adjust it with gamma correction, a powerful technique for fine-tuning visual appearance. Perfect for developers aiming to optimize image presentation, adjust color balance, and ensure consistent rendering across different devices and environments.

Parameters:

ParameterTypeDescription
gammafloatGamma for red, green and blue channels coefficient

Example: The following example performs gamma-correction of a DICOM image.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Set gamma coefficient for red, green and blue channels.
    dicomImage.adjustGamma(2.5f);
    dicomImage.save(dir + "sample.AdjustGamma.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)

public void adjustGamma(float gammaRed, float gammaGreen, float gammaBlue)

Achieve precise color adjustments by applying gamma correction independently to the red, green, and blue components of an image. This method ensures accurate color balance and optimal visual output, catering to developers seeking granular control over image rendering and color accuracy.

Parameters:

ParameterTypeDescription
gammaRedfloatGamma for red channel coefficient
gammaGreenfloatGamma for green channel coefficient
gammaBluefloatGamma for blue channel coefficient

Example: The following example performs gamma-correction of a DICOM image applying different coefficients for color components.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Set individual gamma coefficients for red, green and blue channels.
    dicomImage.adjustGamma(1.5f, 2.5f, 3.5f);
    dicomImage.save(dir + "sample.AdjustGamma.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

adjustBrightness(int brightness)

public void adjustBrightness(int brightness)

Enhance image luminance with the adjustment of brightness, a parameterized method that allows developers to finely tune the luminosity of images. This user-friendly function empowers developers to seamlessly manipulate image brightness, offering flexibility and control over visual aesthetics.

Parameters:

ParameterTypeDescription
brightnessintBrightness value.

Example: The following example performs brightness correction of a DICOM image.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Set the brightness value. The accepted values of brightness are in the range [-255, 255].
    dicomImage.adjustBrightness(50);
    dicomImage.save(dir + "sample.AdjustBrightness.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

adjustContrast(float contrast)

public void adjustContrast(float contrast)

Enhance Image contrast with this user-friendly method, which adjusts the disparity between light and dark areas. Improve visual clarity and definition effortlessly, providing developers with intuitive control over image contrast for optimal rendering.

Parameters:

ParameterTypeDescription
contrastfloatContrast value (in range [-100; 100])

Example: The following example performs contrast correction of a DICOM image.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Set the contrast value. The accepted values of contrast are in the range [-100f, 100f].
    dicomImage.adjustContrast(50f);
    dicomImage.save(dir + "sample.AdjustContrast.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

filter(Rectangle rectangle, FilterOptionsBase options)

public void filter(Rectangle rectangle, FilterOptionsBase options)

Effortlessly enhance specific areas of your image by applying filters to designated rectangles. This method provides developers with precise control over image manipulation, allowing for targeted adjustments to achieve desired visual effects with ease.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle.
optionsFilterOptionsBaseThe options.

Example: The following example applies various types of filters to a DICOM image.

String dir = "c:\\temp\\";

com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Apply a median filter with a rectangle size of 5 to the entire image.
    dicomImage.filter(dicomImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MedianFilterOptions(5));
    dicomImage.save(dir + "sample.MedianFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Apply a bilateral smoothing filter with a kernel size of 5 to the entire image.
    dicomImage.filter(dicomImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.BilateralSmoothingFilterOptions(5));
    dicomImage.save(dir + "sample.BilateralSmoothingFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Apply a Gaussian blur filter with a radius of 5 and a sigma value of 4.0 to the entire image.
    dicomImage.filter(dicomImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussianBlurFilterOptions(5, 4.0));
    dicomImage.save(dir + "sample.GaussianBlurFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Apply a Gauss-Wiener filter with a radius of 5 and a smooth value of 4.0 to the entire image.
    dicomImage.filter(dicomImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.GaussWienerFilterOptions(5, 4.0));
    dicomImage.save(dir + "sample.GaussWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Apply a motion wiener filter with a length of 5, a smooth value of 4.0 and an angle of 90.0 degrees to the entire image.
    dicomImage.filter(dicomImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MotionWienerFilterOptions(10, 1.0, 90.0));
    dicomImage.save(dir + "sample.MotionWienerFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

image = com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Apply a sharpen filter with a kernel size of 5 and a sigma value of 4.0 to the entire image.
    dicomImage.filter(dicomImage.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.SharpenFilterOptions(5, 4.0));
    dicomImage.save(dir + "sample.SharpenFilter.png", new com.aspose.imaging.imageoptions.PngOptions());
} finally {
    image.dispose();
}

resize(int newWidth, int newHeight, ImageResizeSettings settings)

public void resize(int newWidth, int newHeight, ImageResizeSettings settings)

Adjust the size of your image with this simple resizing method. Whether you need to shrink or enlarge your image, this function ensures that your resizing needs are met efficiently and accurately, making it perfect for developers seeking quick and easy image size adjustments.

Parameters:

ParameterTypeDescription
newWidthintThe new width.
newHeightintThe new height.
settingsImageResizeSettingsThe resize settings.

Example: This example loads a DICOM image and resizes it using various resizing settings.

String dir = "c:\\temp\\";

com.aspose.imaging.ImageResizeSettings resizeSettings = new com.aspose.imaging.ImageResizeSettings();

// The adaptive algorithm based on weighted and blended rational function and lanczos3 interpolation.
resizeSettings.setMode(com.aspose.imaging.ResizeType.AdaptiveResample);

// The small rectangular filter
resizeSettings.setFilterType(com.aspose.imaging.ImageFilterType.SmallRectangular);

// The number of colors in the palette.
resizeSettings.setEntriesCount(256);

// The color quantization is not used
resizeSettings.setColorQuantizationMethod(com.aspose.imaging.ColorQuantizationMethod.None);

// The euclidian method
resizeSettings.setColorCompareMethod(com.aspose.imaging.ColorCompareMethod.Euclidian);

com.aspose.imaging.Image image = (com.aspose.imaging.Image) com.aspose.imaging.Image.load(dir + "sample.dicom");
{
    com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = (com.aspose.imaging.fileformats.dicom.DicomImage) image;

    // Scale down by 2 times using adaptive resampling.
    dicomImage.resize(image.getWidth() / 2, image.getHeight() / 2, resizeSettings);

    // Save to PNG
    dicomImage.save(dir + "downsample.adaptive.png", new com.aspose.imaging.imageoptions.PngOptions());
}

cacheData()

public void cacheData()

This method efficiently caches data, optimizing performance and ensuring swift access when needed. Ideal for developers seeking to enhance the speed and efficiency of their applications by intelligently managing data resources.

Example: The following example shows how to cache all pages of a DICOM image.

String dir = "c:\\temp\\";

// Load an image from a DICOM file.
com.aspose.imaging.fileformats.dicom.DicomImage image = (com.aspose.imaging.fileformats.dicom.DicomImage) com.aspose.imaging.Image.load(dir + "sample.dicom");
try {
    // This call caches all the pages so that no additional data loading will be performed from the underlying data stream.
    image.cacheData();

    // Or you can cache the pages individually.
    for (com.aspose.imaging.fileformats.dicom.DicomPage page : image.getDicomPages()) {
        page.cacheData();
    }
} finally {
    image.dispose();
}