Problem in converting standard images to DICOM and Nifti format - image-processing

I have a dataset that contains original MR scans. Each MR scan consists of numerous DICOM images. So for each patient, I have DICOM images in series. The segmentation ground-truth for these scans is available in standard image format (PNG). So each Dicom image has a corresponding ground-truth image in PNG format. My goal is to convert the original scans and ground-truth into Nifti format so that for each study, I have one Nifti scan file and one ground-truth file. I have converted the MR scans (DICOMs) into Nifti, but I have a problem converting the PNG images into Nifti. I first converted the PNG images into dicom images (using the DICOM attributes from original MR scans) and then converted the ground-truth dicoms into nifti. When I convert the ground-truth into DICOM and then to Nifti, it doesn't match the headers of the original MR scan Nifti files. I am not sure why it does that. When I have allocated the DICOM tags with specific properties, it changes them while converting the ground-truth DICOM files to Nifti.
The purpose of doing this is to acquire slices in three views (axial, sagittal, and coronal) once I have Nifti files corresponding to MR scans and their ground-truths.

Related

Image format in segmentation via neural networks

I am doing segmentation via deep learning in pytorch. My dataset is a .raw/.mhd format ultrasound images.
I want to input my dataset into the system via data loader.
I faced few important questions:
Does changing the format of the dataset to either .png or .jpg make the segmentation inaccurate?(I think I lost some information in this way!)
Which format is less data lossy?
How should I make a dumpy array if I don't convert the original image format, i.e., .raw/.mhd?
How should I load this dataset?
Knowing nothing about raw and mhd formats, I can give partial answers.
Firstly, jpg is lossy and png is not. So, you're surely losing information in jpg. png is lossless for "normal" images - 1, 3 or 4 channel, with 8 bit precision in each (perhaps also 16 bits are also supported, don't quote me on that). I know nothing about ultrasound images, but if they use higher precision than that, even png will be lossy.
Secondly, I don't know what mhd is and what raw means in the context of ultrasound images. That being said, a simple google search reveals some package for reading the former to numpy.
Finally, to load the dataset, you can use the ImageFolder class from torchvision. You need to write a custom function which loads an image given its path (for instance using the package mentioned above) and pass it to the loader keyword argument.

Create LMDB for image dataset with k-hot labels

I wanna to create a classifier for an image dataset that each image is in multiple classes from all classes, so the target values are k-hot vectors. Now I create a text file which contains address if image file and space and a k-hot vector in each line but when i try to run scripts to create lmdb files it raise errors that can not open or find files. I try the same process with same data and just a number as class label and everything goes well. So I think it cannot parse .txt file correctly when labels are vectors.
Any suggestion...
Thank you
Caffe "Data" layers and convert_imageset script were written with a very specific use case in mind: image classification. Therefore the basic element stored in (and fetched from) LMDB by caffe is Datum that has a room for a single integer label.
You can see a more lengthy discussion on this subject here
It does not mean Caffe cannot facilitate different types of inputs/tasks.
You can use "HDF5Data" layer instead. When it comes to hdf5 inputs caffe has almost no restrictions on the input shape and size.
See, e.g., this answer and this one for more details on how to actually make it work.

Out of core resampling

I have a large image file (single band) that do not fit in my ram.
I wan to read it as numpy array (data) and plot it using matplotlib, possibly using imshow(data). I know how to do it for a small-sized image. But how can I do it for large file? Ofcourse, its okay to resample (possibly scipy zoom) it before plotting. But how can I resample it before reading as numpy arrray because reading of large file into memory is not possible.
maybe it is better to display the tiff with an external viewer https://superuser.com/questions/254677/what-software-works-well-for-viewing-massive-tiff-images-on-windows-7 .
Otherwise you could try to convert the tiff in an HDF5 file first (ftp://ftp.hdfgroup.org/HDF/contrib/salem/tiffutils.c) , and then load only a part of the matrix you want to display.

IJG library or Windows photo viewer DQT generation

The question is: how Windows photo viewer generates DQ (discrete quantization) tables? And/or how any editor or application which uses IJG library generates DQ tables? I'm trying to find out the algorithm of recomputing this tables when the image is resaved and parameters with help of which it computes them.
The IJG library uses baseline set of quantization tables using the sample one in the JPEG standard (or at least used to). It then uses the "quality" parameter to scale the values in those tables. Off the top of my head, something like quality setting 75 uses the unmodified table. Quality values higher than the baseline scale those values smaller. Lower quality values scale them larger.

Is there a way to compress DICOM data?

Say, I have a sequence on .dicom files in a folder. The cumulative size is about 100 Mb. It's a lot of data. I tried to convert data into .nrrd and .nii, but those files had the summary size of the converted .dicom files (which is fairly predictable, though .nrrd was compressed with gzip). I'd like to know, if there a file format that would give me far less sizes, or just a way to solve that. Perhaps, .vtk, or something else (not sure it qould work). Thanks in advance.
DICOM supports compression of the pixel data within the file itself. The idea of DICOM is that it's format agnostic from the point of view of the pixel data it holds.
DICOM can hold raw pixel data and also can hold JPEG-compressed pixel data, as well as many other formats. The transfer syntax tag of the DICOM file gives you the compression protocol of the pixel data within the DICOM.
The first thing is to figure out whether you need lossless or lossy compression. If lossy, there are a lot of options, and the compression ratio is quite high in some - the tradeoff is that you do lose fidelity and the images may not be adequate for diagnostic purposes. There are also lossless compression schemes - like JPEG2000, RLE and even JPEG-LS. These will compress the pixel data, but retain diagnostic quality without any image degradation.
You can also zip the files, which, if raw, should produce very good results. What are you looking to do w/ these compressed DICOMs?

Resources