Search in sources :

Example 1 with ImageDescriptor

use of org.dcm4che3.imageio.codec.ImageDescriptor in project dcm4chee-arc-light by dcm4che.

the class UncompressedFramesOutput method initDicomInputStream.

private void initDicomInputStream() throws IOException {
    RetrieveService service = ctx.getRetrieveService();
    dis = service.openDicomInputStream(ctx, inst);
    frameLength = new ImageDescriptor(dis.readDataset(-1, Tag.PixelData)).getFrameLength();
    if (dis.tag() != Tag.PixelData) {
        throw new IOException("Missing pixel data in requested object");
    }
}
Also used : RetrieveService(org.dcm4chee.arc.retrieve.RetrieveService) ImageDescriptor(org.dcm4che3.imageio.codec.ImageDescriptor) IOException(java.io.IOException)

Example 2 with ImageDescriptor

use of org.dcm4che3.imageio.codec.ImageDescriptor in project dcm4chee-arc-light by dcm4che.

the class DecompressSupport method initEncapsulatedPixelData.

protected void initEncapsulatedPixelData() throws IOException {
    RetrieveService service = ctx.getRetrieveService();
    dis = service.openDicomInputStream(ctx, inst);
    Attributes attrs = dis.readDataset(-1, Tag.PixelData);
    if (dis.tag() != Tag.PixelData || dis.length() != -1)
        throw new IOException("No or incorrect encapsulated compressed pixel data in requested object");
    ImageDescriptor imageDescriptor = new ImageDescriptor(attrs);
    String tsuid = dis.getTransferSyntax();
    TransferSyntaxType tsType = TransferSyntaxType.forUID(tsuid);
    encapsulatedPixelData = new EncapsulatedPixelDataImageInputStream(dis, imageDescriptor, tsType);
    initDecompressor(tsuid, tsType, imageDescriptor);
    if (tsType == TransferSyntaxType.RLE)
        initBufferedImage(imageDescriptor);
}
Also used : RetrieveService(org.dcm4chee.arc.retrieve.RetrieveService) TransferSyntaxType(org.dcm4che3.imageio.codec.TransferSyntaxType) EncapsulatedPixelDataImageInputStream(org.dcm4che3.imageio.stream.EncapsulatedPixelDataImageInputStream) Attributes(org.dcm4che3.data.Attributes) ImageDescriptor(org.dcm4che3.imageio.codec.ImageDescriptor) IOException(java.io.IOException)

Example 3 with ImageDescriptor

use of org.dcm4che3.imageio.codec.ImageDescriptor in project dcm4chee-arc-light by dcm4che.

the class StoreServiceImpl method selectCompressionRule.

private ArchiveCompressionRule selectCompressionRule(Transcoder transcoder, StoreContext storeContext) {
    ImageDescriptor imageDescriptor = transcoder.getImageDescriptor();
    if (// not an image
    imageDescriptor == null)
        return null;
    if (// already compressed
    transcoder.getSourceTransferSyntaxType() != TransferSyntaxType.NATIVE)
        return null;
    StoreSession session = storeContext.getStoreSession();
    Optional<ArchiveCompressionRule> matchingRule = session.getArchiveAEExtension().compressionRules().filter(rule -> rule.match(session.getRemoteHostName(), session.getCallingAET(), session.getLocalHostName(), session.getCalledAET(), storeContext.getAttributes())).findFirst();
    if (matchingRule.isPresent()) {
        if (!imageDescriptor.isMultiframeWithEmbeddedOverlays()) {
            return matchingRule.get();
        }
        LOG.info("Compression of multi-frame image with embedded overlays not supported");
    }
    return null;
}
Also used : Templates(javax.xml.transform.Templates) SoftwareConfiguration(org.dcm4chee.arc.event.SoftwareConfiguration) Cache(org.dcm4chee.arc.Cache) LoggerFactory(org.slf4j.LoggerFactory) JSONWriter(org.dcm4che3.json.JSONWriter) LeadingCFindSCPQueryCache(org.dcm4chee.arc.LeadingCFindSCPQueryCache) org.dcm4chee.arc.entity(org.dcm4chee.arc.entity) ConfigurationChanges(org.dcm4che3.conf.api.ConfigurationChanges) Transcoder(org.dcm4che3.imageio.codec.Transcoder) SupplementAssigningAuthorities(org.dcm4chee.arc.mima.SupplementAssigningAuthorities) DicomConfiguration(org.dcm4che3.conf.api.DicomConfiguration) UIDUtils(org.dcm4che3.util.UIDUtils) CFindSCUAttributeCoercion(org.dcm4chee.arc.query.scu.CFindSCUAttributeCoercion) CountingInputStream(org.dcm4che3.util.CountingInputStream) MetricsService(org.dcm4chee.arc.metrics.MetricsService) org.dcm4che3.net(org.dcm4che3.net) Collectors(java.util.stream.Collectors) EJBException(javax.ejb.EJBException) HttpServletRequestInfo(org.dcm4chee.arc.keycloak.HttpServletRequestInfo) SAXException(org.xml.sax.SAXException) MergeMWLQueryParam(org.dcm4chee.arc.MergeMWLQueryParam) ApplicationScoped(javax.enterprise.context.ApplicationScoped) org.dcm4chee.arc.store(org.dcm4chee.arc.store) org.dcm4che3.io(org.dcm4che3.io) JsonGenerator(javax.json.stream.JsonGenerator) Socket(java.net.Socket) java.util(java.util) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) MergeMWLCache(org.dcm4chee.arc.MergeMWLCache) ZipInputStream(java.util.zip.ZipInputStream) TransferSyntaxType(org.dcm4che3.imageio.codec.TransferSyntaxType) org.dcm4chee.arc.storage(org.dcm4chee.arc.storage) Function(java.util.function.Function) Inject(javax.inject.Inject) CoercionFactory(org.dcm4chee.arc.coerce.CoercionFactory) HL7Application(org.dcm4che3.net.hl7.HL7Application) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) Json(javax.json.Json) org.dcm4che3.data(org.dcm4che3.data) Event(javax.enterprise.event.Event) OutputStream(java.io.OutputStream) CFindSCU(org.dcm4chee.arc.query.scu.CFindSCU) org.dcm4chee.arc.conf(org.dcm4chee.arc.conf) Logger(org.slf4j.Logger) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) ImageDescriptor(org.dcm4che3.imageio.codec.ImageDescriptor) StringUtils(org.dcm4che3.util.StringUtils) Consumer(java.util.function.Consumer) UnparsedHL7Message(org.dcm4che3.net.hl7.UnparsedHL7Message) InputStream(java.io.InputStream) ImageDescriptor(org.dcm4che3.imageio.codec.ImageDescriptor)

Example 4 with ImageDescriptor

use of org.dcm4che3.imageio.codec.ImageDescriptor in project dcm4che by dcm4che.

the class DicomImageReader method iisOfFrame.

/**
 * Generate an image input stream for the given frame, -1 for all frames (video, multi-component single frame)
 * Does not necessarily support the length operation without seeking/reading to the end of the input.
 *
 * @param frameIndex
 * @return
 * @throws IOException
 */
public ImageInputStream iisOfFrame(int frameIndex) throws IOException {
    ImageInputStream iisOfFrame;
    if (epdiis != null) {
        seekFrame(frameIndex);
        iisOfFrame = epdiis;
    } else if (pixelDataFragments == null) {
        return null;
    } else {
        iisOfFrame = new SegmentedInputImageStream(iis, pixelDataFragments, frames == 1 ? -1 : frameIndex);
        ((SegmentedInputImageStream) iisOfFrame).setImageDescriptor(imageDescriptor);
    }
    return patchJpegLS != null ? new PatchJPEGLSImageInputStream(iisOfFrame, patchJpegLS) : iisOfFrame;
}
Also used : SegmentedInputImageStream(org.dcm4che3.imageio.stream.SegmentedInputImageStream) PatchJPEGLSImageInputStream(org.dcm4che3.imageio.codec.jpeg.PatchJPEGLSImageInputStream) PatchJPEGLSImageInputStream(org.dcm4che3.imageio.codec.jpeg.PatchJPEGLSImageInputStream) EncapsulatedPixelDataImageInputStream(org.dcm4che3.imageio.stream.EncapsulatedPixelDataImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream)

Example 5 with ImageDescriptor

use of org.dcm4che3.imageio.codec.ImageDescriptor in project dcm4che by dcm4che.

the class Transcoder method adjustDataset.

private void adjustDataset() {
    PhotometricInterpretation pmi = imageDescriptor.getPhotometricInterpretation();
    if (decompressor != null) {
        if (imageDescriptor.getSamples() == 3) {
            if (pmi.isYBR() && TransferSyntaxType.isYBRCompression(srcTransferSyntax)) {
                pmi = PhotometricInterpretation.RGB;
                dataset.setString(Tag.PhotometricInterpretation, VR.CS, pmi.toString());
            }
            dataset.setInt(Tag.PlanarConfiguration, VR.US, srcTransferSyntaxType.getPlanarConfiguration());
        } else {
            if (srcTransferSyntaxType.adjustBitsStoredTo12(dataset)) {
                LOG.info("Adjust invalid Bits Stored: {} of {} to 12", imageDescriptor.getBitsStored(), srcTransferSyntaxType);
            }
        }
    }
    if (compressor != null) {
        if (pmi == PhotometricInterpretation.PALETTE_COLOR && lossyCompression) {
            palette2rgb = true;
            dataset.removeSelected(cmTags);
            dataset.setInt(Tag.SamplesPerPixel, VR.US, 3);
            dataset.setInt(Tag.BitsAllocated, VR.US, 8);
            dataset.setInt(Tag.BitsStored, VR.US, 8);
            dataset.setInt(Tag.HighBit, VR.US, 7);
            pmi = PhotometricInterpretation.RGB;
            LOG.warn("Converting PALETTE_COLOR model into a lossy format is not recommended, prefer a lossless format");
        } else if ((pmi.isSubSampled() && !srcTransferSyntaxType.isPixeldataEncapsulated()) || (pmi == PhotometricInterpretation.YBR_FULL && (TransferSyntaxType.isYBRCompression(destTransferSyntax) || destTransferSyntaxType == TransferSyntaxType.JPEG_LS))) {
            ybr2rgb = true;
            pmi = PhotometricInterpretation.RGB;
            LOG.debug("Conversion to an RGB color model is required before compression.");
        } else {
            if (destTransferSyntaxType.adjustBitsStoredTo12(dataset)) {
                LOG.debug("Adjust Bits Stored: {} for {} to 12", imageDescriptor.getBitsStored(), destTransferSyntaxType);
            }
        }
        dataset.setString(Tag.PhotometricInterpretation, VR.CS, pmiForCompression(pmi).toString());
        compressorImageDescriptor = new ImageDescriptor(dataset, bitsCompressed);
        pmi = pmi.compress(destTransferSyntax);
        dataset.setString(Tag.PhotometricInterpretation, VR.CS, pmi.toString());
        if (dataset.getInt(Tag.SamplesPerPixel, 1) > 1)
            dataset.setInt(Tag.PlanarConfiguration, VR.US, destTransferSyntaxType.getPlanarConfiguration());
        if (lossyCompression) {
            dataset.setString(Tag.LossyImageCompression, VR.CS, "01");
            try {
                dataset.setFloat(Tag.LossyImageCompressionRatio, VR.DS, ((Number) compressParam.getClass().getMethod("getCompressionRatiofactor").invoke(compressParam)).floatValue());
            } catch (Exception ignore) {
            }
        }
    }
}
Also used : PhotometricInterpretation(org.dcm4che3.image.PhotometricInterpretation)

Aggregations

ImageDescriptor (org.dcm4che3.imageio.codec.ImageDescriptor)10 BytesWithImageImageDescriptor (org.dcm4che3.imageio.codec.BytesWithImageImageDescriptor)4 Mat (org.opencv.core.Mat)4 RenderedImage (java.awt.image.RenderedImage)3 IOException (java.io.IOException)3 IIOException (javax.imageio.IIOException)3 ImageOutputStream (javax.imageio.stream.ImageOutputStream)3 PhotometricInterpretation (org.dcm4che3.image.PhotometricInterpretation)3 EncapsulatedPixelDataImageInputStream (org.dcm4che3.imageio.stream.EncapsulatedPixelDataImageInputStream)3 MatOfInt (org.opencv.core.MatOfInt)3 ImageCV (org.weasis.opencv.data.ImageCV)3 Attributes (org.dcm4che3.data.Attributes)2 BulkData (org.dcm4che3.data.BulkData)2 TransferSyntaxType (org.dcm4che3.imageio.codec.TransferSyntaxType)2 PatchJPEGLSImageInputStream (org.dcm4che3.imageio.codec.jpeg.PatchJPEGLSImageInputStream)2 SegmentedInputImageStream (org.dcm4che3.imageio.stream.SegmentedInputImageStream)2 RetrieveService (org.dcm4chee.arc.retrieve.RetrieveService)2 EOFException (java.io.EOFException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1