Packages

 

com.aspose.imaging.fileformats.dicom

Class DicomImage

  • All Implemented Interfaces:
    IMultipageImage, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, com.aspose.internal.IPixelsSaver, com.aspose.internal.progressmanagement.IProgressEventHandler, com.aspose.internal.progressmanagement.IProgressInformer, com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public final class DicomImage
    extends RasterCachedMultipageImage

    It is class of the implementation working with image from DICOM file

    Code 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();
    }
    

    • Constructor Detail

      • DicomImage

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

        Initializes a new instance of the DicomImage class.

        Parameters:
        dicomImage - The dicom options (ignoring now).
        width - The width.
        height - The height.
      • DicomImage

        public DicomImage(InputStream stream,
                          LoadOptions loadOptions)

        Initializes a new instance of the DicomImage class.

        Parameters:
        stream - The stream.
        loadOptions - The load options.
        Code example:

        This example shows how to load a DICOM image from a file stream to stay within the specified memory limit.


        String dir = "c:\\temp\\";
        
        // Load a DICOM image from a file stream.
        java.io.FileInputStream stream = new java.io.FileInputStream(dir + "multiframe.dicom");
        try {
            // The max allowed size for all internal buffers is 256KB.
            com.aspose.imaging.LoadOptions loadOptions = new com.aspose.imaging.LoadOptions();
            loadOptions.setBufferSizeHint(256 * 1024);
        
            com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = new com.aspose.imaging.fileformats.dicom.DicomImage(stream, loadOptions);
            try {
                // Save each page as an individual PNG image.
                for (com.aspose.imaging.fileformats.dicom.DicomPage dicomPage : dicomImage.getDicomPages()) {
                    // Generate a file name based on the page index.
                    String fileName = String.format("multiframe.%s.png", dicomPage.getIndex());
        
                    // A DICOM page is a raster image, so all allowed operations with a raster image are applicable to a DICOM page.
                    dicomPage.save(dir + fileName, new com.aspose.imaging.imageoptions.PngOptions());
                }
            } finally {
                dicomImage.dispose();
            }
        } finally {
            stream.close();
        }
        

      • DicomImage

        public DicomImage(InputStream stream)

        Initializes a new instance of the DicomImage class.

        Parameters:
        stream - The stream.
        Code example:

        This example shows how to load a DICOM image from a file stream.


        String dir = "c:\\temp\\";
        
        // Load a DICOM image from a file stream.
        java.io.InputStream stream = new java.io.FileInputStream(dir + "sample.dicom");
        try {
            com.aspose.imaging.fileformats.dicom.DicomImage dicomImage = new com.aspose.imaging.fileformats.dicom.DicomImage(stream);
            try {
                // Save each page as an individual PNG image.
                for (com.aspose.imaging.fileformats.dicom.DicomPage dicomPage : dicomImage.getDicomPages()) {
                    // Generate a file name based on the page index.
                    String fileName = String.format("sample.%s.png", dicomPage.getIndex());
        
                    // A DICOM page is a raster image, so all allowed operations with a raster image are applicable to a DICOM page.
                    dicomPage.save(dir + fileName, new com.aspose.imaging.imageoptions.PngOptions());
                }
            } finally {
                dicomImage.dispose();
            }
        } finally {
            stream.close();
        }
        

    • Method Detail

      • getFileInfo

        public final DicomImageInfo getFileInfo()

        Gets a value, which contains info header the DICOM file

        Returns:
        a value, which contains info header the DICOM file
      • getDicomPages

        public final DicomPage[] getDicomPages()

        Gets the pages.

        Returns:
        the pages.
      • getActivePage

        public final DicomPage getActivePage()

        Gets the active page.

        Returns:
        the active page.
        Throws:
        DicomImageException - The active page cannot be set as it belongs to another image.
      • setActivePage

        public final void setActivePage(DicomPage value)

        Sets the active page.

        Parameters:
        value - the active page.
        Throws:
        DicomImageException - The active page cannot be set as it belongs to another image.
      • getActivePageIndex

        public final int getActivePageIndex()

        Gets the index active page.

        Returns:
        the index active page.
      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
        Returns:
        a value of file format
      • hasAlpha

        public boolean hasAlpha()

        Inform if image has alpha channel.

        Overrides:
        hasAlpha in class RasterCachedMultipageImage
        Returns:
        true if image has alpha channel.
      • saveAll

        public final void saveAll(String filePath,
                                  ImageOptionsBase options)

        Saves the object's data to the specified file (indexer + filename) location in the specified file format according to save options..

        Parameters:
        filePath - The file path.
        options - The options.
      • setResolution

        public void setResolution(double dpiX,
                                  double dpiY)

        Sets the resolution for this RasterImage.

        Overrides:
        setResolution in class RasterImage
        Parameters:
        dpiX - The horizontal resolution, in dots per inch, of the RasterImage.
        dpiY - The vertical resolution, in dots per inch, of the RasterImage.
      • resizeProportional

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

        Performs proportional resize on the image. The proportional resize will resize each frame according to the ratio of newWidth/width and newHeight/height.

        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        resizeType - The resize type.
      • addPage

        public final DicomPage addPage()

        Adds a new page to the end of the page list.

        Returns:
        The newly created DicomPage.
      • insertPage

        public final DicomPage insertPage(int pageIndex)

        Inserts a new page into the page list at the specified index.

        Parameters:
        pageIndex - Index of the page.
        Returns:
        The newly created DicomPage.
        Throws:
        com.aspose.ms.System.ArgumentOutOfRangeException - pageIndex - Page index is less than 0. or pageIndex - Page index is greater than PageCount(RasterCachedMultipageImage.getPageCount()).
        Code 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

        public final void removePage(int pageIndex)

        Removes the page at the specified index of the page list.

        Parameters:
        pageIndex - Index of the page.
        Throws:
        com.aspose.ms.System.ArgumentOutOfRangeException - pageIndex - Page index is less than 0. or pageIndex - Page index is equal to or greater than PageCount(RasterCachedMultipageImage.getPageCount()).
      • rotate

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

        RasterCachedMultipageImage.rotate image around the center.

        Overrides:
        rotate in class RasterCachedMultipageImage
        Parameters:
        angle - The rotate angle in degrees. Positive values will rotate clockwise.
        resizeProportionally - if 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.
        backgroundColor - Color of the background.
        Code 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

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

        Resizes the image.

        Overrides:
        resize in class RasterCachedMultipageImage
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        resizeType - The resize type.
        Code 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

        public void resizeWidthProportionally(int newWidth,
                                              int resizeType)

        Resizes the width proportionally.

        Overrides:
        resizeWidthProportionally in class RasterCachedMultipageImage
        Parameters:
        newWidth - The new width.
        resizeType - Type of the resize.
        Code example:

        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

        public void resizeHeightProportionally(int newHeight,
                                               int resizeType)

        Resizes the width proportionally.

        Overrides:
        resizeHeightProportionally in class RasterCachedMultipageImage
        Parameters:
        newHeight - The new height.
        resizeType - Type of the resize.
        Code example:

        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

        public void rotateFlip(int rotateFlipType)

        Rotates, flips, or rotates and flips the Active frame only.

        Overrides:
        rotateFlip in class RasterCachedMultipageImage
        Parameters:
        rotateFlipType - The rotate flip type.
        See Also:
        RotateFlipType
        Code 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

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

        Performs dithering on the current image.

        Overrides:
        dither in class RasterCachedMultipageImage
        Parameters:
        ditheringMethod - The dithering method.
        bitsCount - The final bits count for dithering.
        customPalette - The custom palette for dithering.
        Code 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

        public void crop(Rectangle rectangle)

        Cropping the image.

        Overrides:
        crop in class RasterCachedMultipageImage
        Parameters:
        rectangle - The rectangle.
        Code example:

        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

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

        Crop image with shifts.

        Overrides:
        crop in class RasterCachedMultipageImage
        Parameters:
        leftShift - The left shift.
        rightShift - The right shift.
        topShift - The top shift.
        bottomShift - The bottom shift.
        Code example:

        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

        public void binarizeFixed(byte threshold)

        Binarization of an image with predefined threshold

        Overrides:
        binarizeFixed in class RasterCachedMultipageImage
        Parameters:
        threshold - Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.
        Code example:

        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()

        Binarization of an image with Otsu thresholding

        Overrides:
        binarizeOtsu in class RasterCachedMultipageImage
        Code example:

        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

        public void binarizeBradley(double brightnessDifference,
                                    int windowSize)

        Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding

        Overrides:
        binarizeBradley in class RasterCachedMultipageImage
        Parameters:
        brightnessDifference - The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
        windowSize - The size of s x s window of pixels centered around this pixel
        Code example:

        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()

        Transformation of an image to its grayscale representation

        Overrides:
        grayscale in class RasterCachedMultipageImage
        Code example:

        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

        public void adjustGamma(float gamma)

        Gamma-correction of an image.

        Overrides:
        adjustGamma in class RasterCachedMultipageImage
        Parameters:
        gamma - Gamma for red, green and blue channels coefficient
        Code 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

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

        Gamma-correction of an image.

        Overrides:
        adjustGamma in class RasterCachedMultipageImage
        Parameters:
        gammaRed - Gamma for red channel coefficient
        gammaGreen - Gamma for green channel coefficient
        gammaBlue - Gamma for blue channel coefficient
        Code 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

        public void adjustBrightness(int brightness)

        Adjust of a brightness for image.

        Overrides:
        adjustBrightness in class RasterCachedMultipageImage
        Parameters:
        brightness - Brightness value.
        Code 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

        public void adjustContrast(float contrast)

        Image contrasting

        Overrides:
        adjustContrast in class RasterCachedMultipageImage
        Parameters:
        contrast - Contrast value (in range [-100; 100])
        Code 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

        public void filter(Rectangle rectangle,
                           FilterOptionsBase options)

        Filters the specified rectangle.

        Overrides:
        filter in class RasterCachedMultipageImage
        Parameters:
        rectangle - The rectangle.
        options - The options.
        Code 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

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

        Resizes the image.

        Overrides:
        resize in class RasterCachedMultipageImage
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        settings - The resize settings.
        Code 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()

        Caches the data private.

        Overrides:
        cacheData in class RasterCachedMultipageImage
        Code 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();
        }