Search in sources :

Example 1 with MaskArea

use of org.dcm4che3.img.op.MaskArea in project karnak by OsiriX-Foundation.

the class Profile method applyCleanPixelData.

public void applyCleanPixelData(Attributes dcmCopy, AttributeEditorContext context, ProfileEntity profileEntity) {
    Object pix = dcmCopy.getValue(Tag.PixelData);
    if ((pix instanceof BulkData || pix instanceof Fragments) && !profileEntity.getMaskEntities().isEmpty() && profiles.stream().anyMatch(p -> p instanceof CleanPixelData)) {
        String sopClassUID = dcmCopy.getString(Tag.SOPClassUID);
        if (!StringUtil.hasText(sopClassUID)) {
            throw new IllegalStateException("DICOM Object does not contain sopClassUID");
        }
        String scuPattern = sopClassUID + ".";
        MaskArea mask = getMask(dcmCopy.getString(Tag.StationName));
        // BurnedInAnnotation
        if (isCleanPixelAllowedDependingImageType(dcmCopy, sopClassUID, scuPattern) && evaluateConditionCleanPixelData(dcmCopy)) {
            context.setMaskArea(mask);
            if (mask == null) {
                throw new IllegalStateException("Clean pixel is not applied: mask not defined in station name");
            }
        } else {
            context.setMaskArea(null);
        }
    }
}
Also used : Color(java.awt.Color) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) VR(org.dcm4che3.data.VR) Attributes(org.dcm4che3.data.Attributes) ReplaceNull(org.karnak.backend.model.action.ReplaceNull) LoggerFactory(org.slf4j.LoggerFactory) MarkerFactory(org.slf4j.MarkerFactory) HashMap(java.util.HashMap) StringUtil(org.weasis.core.util.StringUtil) Remove(org.karnak.backend.model.action.Remove) ArrayList(java.util.ArrayList) SecretEntity(org.karnak.backend.data.entity.SecretEntity) Map(java.util.Map) ProfileItem(org.karnak.backend.model.profiles.ProfileItem) ProjectEntity(org.karnak.backend.data.entity.ProjectEntity) BigInteger(java.math.BigInteger) BulkData(org.dcm4che3.data.BulkData) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) ActionItem(org.karnak.backend.model.action.ActionItem) ExpressionResult(org.karnak.backend.model.expression.ExpressionResult) ExprCondition(org.karnak.backend.model.expression.ExprCondition) Shape(java.awt.Shape) DefacingUtil.isAxial(org.karnak.backend.dicom.DefacingUtil.isAxial) HMAC(org.karnak.backend.model.profilepipe.HMAC) Logger(org.slf4j.Logger) ActionTags(org.karnak.backend.model.profiles.ActionTags) Set(java.util.Set) HashContext(org.karnak.backend.model.profilepipe.HashContext) CleanPixelData(org.karnak.backend.model.profiles.CleanPixelData) Collectors(java.util.stream.Collectors) TagUtils(org.dcm4che3.util.TagUtils) List(java.util.List) ProfileItemType(org.karnak.backend.enums.ProfileItemType) Tag(org.dcm4che3.data.Tag) Marker(org.slf4j.Marker) MDC(org.slf4j.MDC) Sequence(org.dcm4che3.data.Sequence) Defacer(org.karnak.backend.dicom.Defacer) Fragments(org.dcm4che3.data.Fragments) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) DefacingUtil.isCT(org.karnak.backend.dicom.DefacingUtil.isCT) Comparator(java.util.Comparator) Collections(java.util.Collections) Defacing(org.karnak.backend.model.profiles.Defacing) MaskArea(org.dcm4che3.img.op.MaskArea) CleanPixelData(org.karnak.backend.model.profiles.CleanPixelData) Fragments(org.dcm4che3.data.Fragments) BulkData(org.dcm4che3.data.BulkData) MaskArea(org.dcm4che3.img.op.MaskArea)

Example 2 with MaskArea

use of org.dcm4che3.img.op.MaskArea in project karnak by OsiriX-Foundation.

the class Profile method createProfilesList.

public List<ProfileItem> createProfilesList(final ProfileEntity profileEntity) {
    if (profileEntity != null) {
        List<ProfileItem> profileItems = getProfileItems(profileEntity);
        profileEntity.getMaskEntities().forEach(m -> {
            Color color = null;
            if (StringUtil.hasText(m.getColor())) {
                color = ActionTags.hexadecimal2Color(m.getColor());
            }
            List<Shape> shapeList = m.getRectangles().stream().map(Shape.class::cast).collect(Collectors.toList());
            addMask(m.getStationName(), new MaskArea(shapeList, color));
        });
        return profileItems;
    }
    return Collections.emptyList();
}
Also used : ProfileItem(org.karnak.backend.model.profiles.ProfileItem) Shape(java.awt.Shape) Color(java.awt.Color) MaskArea(org.dcm4che3.img.op.MaskArea)

Example 3 with MaskArea

use of org.dcm4che3.img.op.MaskArea in project karnak by OsiriX-Foundation.

the class ForwardService method transformImage.

private static Editable<PlanarImage> transformImage(Attributes attributes, AttributeEditorContext context) {
    MaskArea m = context.getMaskArea();
    boolean defacing = LangUtil.getEmptytoFalse(context.getProperties().getProperty(Defacer.APPLY_DEFACING));
    if (m != null || defacing) {
        return img -> {
            PlanarImage image = img;
            if (defacing) {
                image = Defacer.apply(attributes, image);
            }
            if (m != null) {
                image = MaskArea.drawShape(image.toMat(), m);
            }
            return image;
        };
    }
    return null;
}
Also used : AttributeEditor(org.weasis.dicom.param.AttributeEditor) HttpException(org.weasis.dicom.web.HttpException) DataWriter(org.dcm4che3.net.DataWriter) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) UID(org.dcm4che3.data.UID) Attributes(org.dcm4che3.data.Attributes) BytesWithImageDescriptor(org.dcm4che3.img.stream.BytesWithImageDescriptor) ForwardDestination(org.karnak.backend.dicom.ForwardDestination) AbortException(org.karnak.backend.exception.AbortException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) ImageAdapter(org.dcm4che3.img.stream.ImageAdapter) Service(org.springframework.stereotype.Service) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) InputStreamDataWriter(org.dcm4che3.net.InputStreamDataWriter) StoreFromStreamSCU(org.weasis.dicom.util.StoreFromStreamSCU) TransferStatusEntity(org.karnak.backend.data.entity.TransferStatusEntity) FileUtil(org.weasis.core.util.FileUtil) DicomOutputData(org.dcm4che3.img.DicomOutputData) Editable(org.dcm4che3.img.util.Editable) PDVInputStream(org.dcm4che3.net.PDVInputStream) LangUtil(org.weasis.core.util.LangUtil) PlanarImage(org.weasis.opencv.data.PlanarImage) Logger(org.slf4j.Logger) Params(org.karnak.backend.dicom.Params) IncludeBulkData(org.dcm4che3.io.DicomInputStream.IncludeBulkData) DataWriterAdapter(org.dcm4che3.net.DataWriterAdapter) DicomStowRS(org.weasis.dicom.web.DicomStowRS) Set(java.util.Set) AdaptTransferSyntax(org.dcm4che3.img.stream.ImageAdapter.AdaptTransferSyntax) IOException(java.io.IOException) Status(org.dcm4che3.net.Status) ProgressStatus(org.weasis.dicom.util.ServiceUtil.ProgressStatus) File(java.io.File) TransferMonitoringEvent(org.karnak.backend.model.event.TransferMonitoringEvent) Association(org.dcm4che3.net.Association) List(java.util.List) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) Tag(org.dcm4che3.data.Tag) ServiceUtil(org.weasis.dicom.util.ServiceUtil) DicomInputStream(org.dcm4che3.io.DicomInputStream) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) Abort(org.weasis.dicom.param.AttributeEditorContext.Abort) Defacer(org.karnak.backend.dicom.Defacer) MaskArea(org.dcm4che3.img.op.MaskArea) InputStream(java.io.InputStream) MaskArea(org.dcm4che3.img.op.MaskArea) PlanarImage(org.weasis.opencv.data.PlanarImage)

Aggregations

MaskArea (org.dcm4che3.img.op.MaskArea)3 Color (java.awt.Color)2 Shape (java.awt.Shape)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 Attributes (org.dcm4che3.data.Attributes)2 Tag (org.dcm4che3.data.Tag)2 Defacer (org.karnak.backend.dicom.Defacer)2 ProfileItem (org.karnak.backend.model.profiles.ProfileItem)2 Logger (org.slf4j.Logger)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1