Пример #1
0
    public static bool ProcessOneFile(string filename, string outfilename)
    {
        PixmapReader reader = new PixmapReader();

        reader.SetFileName(filename);
        if (!reader.Read())
        {
            System.Console.WriteLine("Could not read: " + filename);
            return(false);
        }

        ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();

        change.SetForce(false);             // do we really want to recompress when input is alread compressed in same alg ?
        change.SetCompressIconImage(false); // Keep it simple
        change.SetTransferSyntax(new TransferSyntax(TransferSyntax.TSType.JPEG2000Lossless));
        change.SetInput(reader.GetPixmap());
        if (!change.Change())
        {
            System.Console.WriteLine("Could not change: " + filename);
            return(false);
        }

        gdcm.FileMetaInformation fmi = reader.GetFile().GetHeader();
        // The following three lines make sure to regenerate any value:
        fmi.Remove(new gdcm.Tag(0x0002, 0x0012));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0013));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0016));

        PixmapWriter writer = new PixmapWriter();

        writer.SetFileName(outfilename);
        writer.SetFile(reader.GetFile());
        gdcm.Bitmap bitout = change.GetOutput();
        gdcm.Pixmap pixout = (gdcm.Pixmap)bitout;
        //System.Console.WriteLine( "Debug: " + pixout.toString() );

        writer.SetPixmap(pixout);
        if (!writer.Write())
        {
            System.Console.WriteLine("Could not write: " + outfilename);
            return(false);
        }

        return(true);
    }
Пример #2
0
    public static int Main(string[] args)
    {
        gdcm.FileMetaInformation.SetSourceApplicationEntityTitle("My Reformat App");

        // http://www.oid-info.com/get/1.3.6.1.4.17434
        string THERALYS_ORG_ROOT = "1.3.6.1.4.17434";

        gdcm.UIDGenerator.SetRoot(THERALYS_ORG_ROOT);
        System.Console.WriteLine("Root dir is now: " + gdcm.UIDGenerator.GetRoot());

        string filename    = args[0];
        string outfilename = args[1];

        Reader reader = new Reader();

        reader.SetFileName(filename);
        if (!reader.Read())
        {
            System.Console.WriteLine("Could not read: " + filename);
            return(1);
        }

        UIDGenerator   uid = new UIDGenerator(); // helper for uid generation
        FileDerivation fd  = new FileDerivation();
        // For the pupose of this execise we will pretend that this image is referencing
        // two source image (we need to generate fake UID for that).
        string ReferencedSOPClassUID = "1.2.840.10008.5.1.4.1.1.7"; // Secondary Capture

        fd.AddReference(ReferencedSOPClassUID, uid.Generate());
        fd.AddReference(ReferencedSOPClassUID, uid.Generate());

        // Again for the purpose of the exercise we will pretend that the image is a
        // multiplanar reformat (MPR):
        // CID 7202 Source Image Purposes of Reference
        // {"DCM",121322,"Source image for image processing operation"},
        fd.SetPurposeOfReferenceCodeSequenceCodeValue(121322);
        // CID 7203 Image Derivation
        // { "DCM",113072,"Multiplanar reformatting" },
        fd.SetDerivationCodeSequenceCodeValue(113072);
        fd.SetFile(reader.GetFile());
        // If all Code Value are ok the filter will execute properly
        if (!fd.Derive())
        {
            return(1);
        }

        gdcm.FileMetaInformation fmi = reader.GetFile().GetHeader();
        // The following three lines make sure to regenerate any value:
        fmi.Remove(new gdcm.Tag(0x0002, 0x0012));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0013));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0016));

        Writer writer = new Writer();

        writer.SetFileName(outfilename);
        writer.SetFile(fd.GetFile());
        if (!writer.Write())
        {
            System.Console.WriteLine("Could not write: " + outfilename);
            return(1);
        }


        return(0);
    }
Пример #3
0
    public static bool ProcessOneFile(gdcm.Anonymizer ano, string filename, string outfilename)
    {
        Reader reader = new Reader();

        reader.SetFileName(filename);
        bool ret = reader.Read();

        if (!ret)
        {
            return(false);
        }
        // Pass in the file:
        ano.SetFile(reader.GetFile());

        // First step, let's protect all Patient information as per
        // PS 3.15 / E.1 / Basic Application Level Confidentiality Profile
        if (!ano.BasicApplicationLevelConfidentialityProfile())
        {
            return(false);
        }

        // Now let's pass in all Clinical Trial fields
        // PS 3.3 - 2008 / C.7.1.3 Clinical Trial Subject Module

        /*
         * Clinical Trial Sponsor Name (0012,0010) 1 The name of the clinical trial sponsor. See C.7.1.3.1.1.
         * Clinical Trial Protocol ID (0012,0020) 1 Identifier for the noted protocol. See C.7.1.3.1.2.
         * Clinical Trial Protocol Name (0012,0021) 2 The name of the clinical trial protocol. See C.7.1.3.1.3.
         * Clinical Trial Site ID (0012,0030) 2 The identifier of the site responsible for submitting clinical trial data. See C.7.1.3.1.4.
         * Clinical Trial Site Name (0012,0031) 2 Name of the site responsible for submitting clinical trial data. See C.7.1.3.1.5
         * Clinical Trial Subject ID (0012,0040) 1C The assigned identifier for the clinical trial subject. See C.7.1.3.1.6. Shall be present if Clinical Trial Subject Reading ID (0012,0042) is absent. May be present otherwise.
         * Clinical Trial Subject Reading ID (0012,0042) 1C Identifies the subject for blinded evaluations. Shall be present if Clinical Trial Subject ID (0012,0040) is absent.  May be present otherwise. See C.7.1.3.1.7.
         */
        ano.Replace(new gdcm.Tag(0x0012, 0x0010), "MySponsorName");
        ano.Replace(new gdcm.Tag(0x0012, 0x0020), "MyProtocolID");
        ano.Replace(new gdcm.Tag(0x0012, 0x0021), "MyProtocolName");
        ano.Replace(new gdcm.Tag(0x0012, 0x0030), "MySiteId");
        ano.Replace(new gdcm.Tag(0x0012, 0x0031), "MySiteName");
        ano.Replace(new gdcm.Tag(0x0012, 0x0040), "MySponsorId");
        ano.Replace(new gdcm.Tag(0x0012, 0x0050), "MyTPId");
        ano.Replace(new gdcm.Tag(0x0012, 0x0051), "MyTPDescription");

        // The following two are not required as they are guaranteed to be filled in by the
        // Basic Application Level Confidentiality Profile. Only override if you understand what
        // you are doing
        //ano.Replace( new gdcm.Tag(0x0012,0x0062), "YES");
        //ano.Replace( new gdcm.Tag(0x0012,0x0063), "My Super Duper Anonymization Overload");

        // We might be generating a subdirectory. Let's make sure the subdir exist:
        gdcm.Filename fn     = new gdcm.Filename(outfilename);
        string        subdir = fn.GetPath();

        if (!gdcm.PosixEmulation.MakeDirectory(subdir))
        {
            return(false);
        }

        gdcm.FileMetaInformation fmi = ano.GetFile().GetHeader();
        // The following three lines make sure to regenerate any value:
        fmi.Remove(new gdcm.Tag(0x0002, 0x0012));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0013));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0016));

        Writer writer = new Writer();

        writer.SetFileName(outfilename);
        writer.SetFile(ano.GetFile());
        ret = writer.Write();
        if (!ret)
        {
            return(false);
        }

        return(true);
    }