I am trying to create a new DICOM file from an existing DICOM file. So, the scenario is that I have a DICOM file and I do some image processing on it and produce a transformed/processed file and I would like to save it using the original file as a template.
The only things that change are
1: The pixel data
2: The rescale and offset tags.
Does anyone know how I can achieve this with DCMTK? I looked at various examples but most of them show how to save a JPG or BMP image into a new DICOM file.
If you modify the image data (Pixel Data), you should save the new dataset with new Series Instance UID and SOP Instance UID. In addition, you should also update the first value of Image Type (0008, 0008) to “DERIVED” to reflect that image is not the original image. The second value Image Type tag can be “PRIMARY” or “SECONDARY” depending on the patient examination characteristics. You can also use Derivation Description (0008, 2111) and Derivation Code Sequence (0008,9215) to describe the way in which the image was derived. In addition, you can also reference the source image(s) used to create the Derived image by adding optional Source Image Sequence (0008,2112) which can hold a list of Referenced SOP Class UID (0008,1150)/ Referenced SOP Instance UID (0008,1150) pair(s).
Kinldy check dcmodify executable and check the help in command, it has the option to modify the tags.
For anything but pixel data dcmodify is the tool of your choice.
For the pixel data you can use dcmdump to extract the pixel data to a RAW file, change it and use dump2dcm to re-integrate it into the DICOM file
Related
I want to make some basic math stuff like Sum in Diagrams.net (old Draw.io).Is it possible ?
Exemple : I create a new parameter on a shape, like "Elec : T16" and make several copy on this shape. Is it possible to have a Text which can give me the total of the shape with this parameter ?
Best Regards.
I search a lot in the Diagrams.net blog but anything relevent.
This is not supported.
Regards,
I also wanted to do something similar and while it doesn't seem possible to do it completely in the software (as of v20.3.0), I did find a bit of a workaround: If you add properties to the shape data, then do File > Export As > XML, the properties will be there in the XML data. You can then count them one of two ways:
Open the XML file with a text editor like Notepad++, do a find on the value you want to count. If you choose "Find All" it will tell you how many times it appears.
Use a programming language like Python to read through the file and count the instances of that value.
Example:
I created a red circle in a new diagram, edited the text to say "RedCircle" and used Edit Data to add a property called TestValue, to which I assigned a value of 1. When I exported to XML it contained this element:
<object label="RedCircle" TestValue="1" id="6byQ5fOap-RXn7mFit_J-1">
Notes
When you export, make sure you turn off the Compressed option, this will create an unusable file.
Don't use Save As > XML, this will also use compression.
Diagrams.net natively saves in a compressed XML format, with only slight differences between that and the other compressed XML options, but it seems happy to also read in the exported uncompressed XML. I didn't test but if you go the programming route and want to take it a step further, it seems you could have the program update the value of a given "counter" element with the count, then open the XML file in diagrams.net to see the updated value and save it as a native .drawio file or publish in whatever format you like.
Edit: I discovered that under File > Properties you can turn off the compression on the actual .drawio file. If you do that you can just work from this file instead of exporting, but you might want to check the size of your file with and without it.
I'm sure a plugin could be created to do all of that within the app itself, but the other methods are enough for me at this point.
Hope this helps you!
I would like to read DICOM private tags. These private tags are under hexadecimal tag x7fe11001.
I know one of the pydicom configurations that read till pixel data starts (so the memory is not loaded up).
pydicom.dcmread(raw, defer_size="2 MB", stop_before_pixels=True)
But the private tags I am trying to read are after the pixel data. So I am ending loading complete file in memory which is not optimal. What are the other ways to read it in an optimal way?
I know there is a config param for the above method, called specific_tags. But I could not find any examples of how to use it.
Any suggestions to read DICOM metadata without loading pixel data into memory would be awesome.
You are right, specific_tags is the correct way to do this:
ds = pydicom.dcmread(raw, specific_tags=[Tag(0x7fe1, 0x1001)]
In this case, ds shall contain only your private tag and the Specific Character Set tag (which is always read).
As DICOM is a sequential format, the other tags still have to be skipped over one by one, but their value is not read.
Note that you can put any number of tags into the specific_tags argument.
I´m using the FileServlet from Omnifaces:
http://showcase.omnifaces.org/servlets/FileServlet
It works fine and all my images appears in my webapp.
But now I would like to change the link from the image because I would like to avoid that someone enter the path from another image:
For example:
The path from one image is:
myapp/imagesservlet/mypic1.jpg
-> Someone can enter
myapp/imagesservlet/mypic2.jpg -> and got another image.
My files are stored as:
mypic like mypic1.jpg, mypic2.jpg.....
Is there any chance to change the path and got also the correct image?
Just use unpredictable autogenerated filenames. E.g. imgur also does that. This responsibility is actually beyond the OmniFaces FileServlet as all it does is just inspecting the passed-in filename and serving it up. You should change the passed-in filename to be an autogenerated one. Save if necessary the original filename somewhere else, e.g. in a SQL database, if necessary along with other metadata (content type, size, etc) so it can more efficiently be indexed and searched.
How to autogenerate a random string in Java is already covered in this Q&A: How to generate a random alpha-numeric string?
I am working with DCMTK to modify an input DICOM file.
This is a Multi-Frame DICOM file on my disk. I need to add new frames into the PixelData element, and save the output using the same input filename.
The restriction is that I can not load the whole PixelData in memory. I would like to append new frame to the end of DICOM file, directly. Does anyone have any idea on how to do this ?
Too bad you are using DCMTK, if instead you were using GDCM, you could simply instantiate the FileStreamer class and append any Pixel Data chunk you would like:
See FileStreamer documentation.
I would like to generate an image using text and a custom font.
As it is mentioned here Output text as GIF or PNG for use in eBook
How can I store the file in my content's file field?
All you need to do is call the field accessor with a file-like object, preferably one that includes the file mime-type (image/png or image/gif in your case). Zope's OFS.File.File provides such info. Let's say your file field is simply called file (so it's setter is called setFile) and you have your image in a string variable named imagedata containing a PNG image:
from OFS.Image import File
image = File('ignored-id', 'ignored-title', imagedata, 'image/png')
contentobject.setFile(image)
Note that you may want to change your field to type ImageField though; it provides a richer interface for images, including HTML tag generation and scaling.
Get the python file-like object corresponding to the image and pass it as an argument to the field mutator method. If the field if called fooImage, then the mutator, by default, is object.setFooImage(image_file_here). Or you could pass it in using the object.update(fooImage=image_file_here) method.