How to convert the annotation label? - semantic-segmentation

I have a question about the conversion of images.
In segmentation tasks of medical images, if DICOM files are converted to NifTI files with dicom2nifti, discrepancies could occur between original images and annotation labels.
How to correct these discrepancies?? Thanks in advance.
I tried:
label = scipy.io.loadmat("./annotation_label")
label = label["Mask"]
label_nif = nib.nifti1.Nifti1Image(label, affine=None)
I know affine is required, but how to calculate the affine which converts DICOM to NifTI?
I converted the original DICOM files to NIfTI files, and the original annotation label (numpy file) to NifTI files.
Then, discrepancies occurred...

Related

How can I convert large number of EPS files to PNG with a desired sizing?

I have bulk images in EPS having varied dimensions, all stored in a one folder.
How can I convert them all to PNG having a fixed dimension of 4500x5400 and make them store in another folder?
Can this process be done in one go, instead of manually doing it for each image?

How to open a .img/.rrd satellite image in Matlab?

I have a couple of multispectral satellite images which are in .img/.rrd format and I want to oopen them in Matlab for further processing.
I'm not sure Matlab can recognise .img /.rdd files directly, but you could try using ImageJ or Fiji to convert your .img files to one of the image formats that is accepted. e.g. tiff, png, bmp, jpeg. The list of accepted formats can be found by typing 'imformats' in the command line.

Convert dicom .dcm files into .obj format

I have sets of .dcm files of an MRI scan. I am trying to convert them into 3d formats like obj (preferably) or fbx to import them into Unity 3d. I used the following open source software dcmtk to convert .dcm file into text file.
Converting DICOM files to text files
However, the dcm files lack the needed information. Is it even possible to convert .dcm files to obj and fbx. if so, could you suggest something?
Thanks
(Edit)
I would like to put my question more precisely: I want to visualize MRI data as a 3D model in Unity 3d. This is possible only when I it stored as .obj or .fbx format. Which format of MRI medical data should I start with to convert to these formats?
Thanks
According to your previous comments you are looking for the necessary information in order to obtain the geometrical information of a DICOM series representing volumetric information (RM, TC, PET, ...)
In this case, you should have a look at the Roni Zaharia web site where he explains very clearly the concepts related to orientation and geometry of the DICOM images: DICOM is easy: Getting oriented
In this particular page you will find information about Pixel Spacing, Image Orientation, Image Position, Slice Thickness, and Slice Location, as well as additional information references.

Matlab: how to save TIFF with transparency or PNG with no compression?

I have to process a lot of images and save results to image files with transparency in Matlab. But PNG compression takes too much time for me. How can I save PNG with no compression or TIFF with transparency? Are there other ways to save an image without compression and with transparency?
It's my first question here, sorry for my bad English and wrong question style if there are any mistakes in question.
Using the TIFF class in Matlab you can write TIFFs with transparancy:
%# create a synthetic RGBA image
ch = checkerboard(100);
rgba = repmat(ch,[1,1,4]);
rgba(:,:,4) = rgba(:,:,4)==0;
rgba = uint8(round(rgba*255));
%# create a tiff object
tob = Tiff('test.tif','w');
%# you need to set Photometric before Compression
tob.setTag('Photometric',Tiff.Photometric.RGB)
tob.setTag('Compression',Tiff.Compression.None)
%# tell the program that channel 4 is alpha
tob.setTag('ExtraSamples',Tiff.ExtraSamples.AssociatedAlpha)
%# set additional tags (you may want to use the structure
%# version of this for convenience)
tob.setTag('ImageLength',size(ch,1));
tob.setTag('ImageWidth',size(ch,2));
tob.setTag('BitsPerSample',8);
tob.setTag('RowsPerStrip',16);
tob.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
tob.setTag('Software','MATLAB')
tob.setTag('SamplesPerPixel',4);
%# write and close the file
tob.write(rgba)
tob.close
%# open in Photoshop - see transparency!
Matlab's imwrite does not have parameter for the PNG compression level. If it did, you could set it to zero for no compression. While for TIFF it does have a none option for Compression, there is no alpha channel. You can write to the old Sun Raster (RAS) format with an alpha channel and no compression. Though nothing would likely be able to read it.
"There is no uncompressed variant of PNG. It is possible to store uncompressed data by using only uncompressed deflate block"
The uncompressed deflate block uses a header of 5 bytes + up to 65535 bytes of uncompressed data per block.
http://www.w3.org/TR/PNG-Rationale.html

Matlab: How to save plots of patches / fill() automatically in the code?

quick question: I'm creating "random" polygons using either the patch() or the fill() function in Matlab. This works quite good and it is plotted correctly.
However, I need to at least save a few hundres polygons as images to my hard drive for working with them later - so I'm looking for a way to directly save the image in my function rather than saving each polygon myself using the file-menu.
Is there any way to do this?
Thanks in advance!
You can indeed use the print function, but I would not use the jpeg device. JPEG is never the right format for plots (you will get a lot of artifacts near all your lines).
If you need a bitmap image, try the png or tiff device. If you don't need a bitmap, use the appropriate vector image format: fig is the native MATLAB format (which allows you to edit the plot afterwards), so this is the best one if you stick with MATLAB for all your operations. For exporting to other software, I would recommend pdf (works almost anywhere), epsc (EPS with color, great for LaTeX or inkscape), wmf/emf (Windows Metafile, so Windows only, but great for including the images in MS Office). Or you could of course use any of the other formats mentioned in the print documentation.
Sometimes it's a pain in the neck to get the format of your image all right (especially with PDF output). Just take a look at the different properties of your figure and more specifically the PaperSize, PaperUnits and PaperPosition.
The easiest way, and I guess the best solution, is to save as a .fig file. You can do this by using saveas:
h = figure;
% your plot commands here
saveas(h,'mFile.fig');
Afterwards, you can reload the image with the openfig function:
openfig('mFile.fig');
Have to add this answer. This function is helping a lot.
This function saves a figure or single axes to one or more vector and/or bitmap file formats, and/or outputs a rasterized version to the workspace, with the following properties:
   - Figure/axes reproduced as it appears on screen
   - Cropped/padded borders (optional)
   - Embedded fonts (pdf only)
   - Improved line and grid line styles
   - Anti-aliased graphics (bitmap formats)
   - Render images at native resolution (optional for bitmap formats)
   - Transparent background supported (pdf, eps, png)
   - Semi-transparent patch objects supported (png only)
   - RGB, CMYK or grayscale output (CMYK only with pdf, eps, tiff)
   - Variable image compression, including lossless (pdf, eps, jpg)
   - Optionally append to file (pdf, tiff)
   - Vector formats: pdf, eps
   - Bitmap formats: png, tiff, jpg, bmp, export to workspace