How to Display .raw Dataset? - python

I'm trying to write a script to display the images in the file burned_wood_with_tape_1664x512x256_12bit.raw from this website: https://figshare.com/articles/SSOCT_test_dataset_for_OCTproZ/12356705
for a research project. However, I can't find a way to display the images in this .raw dataset.
This is the software I have, using other questions on StackOverflow:
import rawpy
import imageio
path = "Datasets/burned_wood_with_tape_1664x512x256_12bit.raw"
for item in path:
item_path = path + item
raw = rawpy.imread(item_path)
rgb = raw.postprocess()
rawpy.imshow(rgb)
But I get this error:
Traceback (most recent call last):
File "[ENTER PATH]", line 7, in <module>
raw = rawpy.imread(item_path)
File "[ENTER PATH]\lib\site-packages\rawpy\__init__.py", line 20, in imread
d.open_file(pathOrFile)
File "rawpy\_rawpy.pyx", line 404, in rawpy._rawpy.RawPy.open_file
File "rawpy\_rawpy.pyx", line 914, in rawpy._rawpy.RawPy.handle_error
rawpy._rawpy.LibRawIOError: b'Input/output error'

The data that you have is not a ".raw" file. It is a dataset that can be used with the "Virtual OCT System" of OCTproZ (https://github.com/spectralcode/OCTproZ/). The "rawpy" library is not useful in this case. That library works for ".raw" photos.

Related

Conversion not working properly using dicom2nifti

I have a series of dicom files (.dcm) for each patient that I want to convert to nii.gz files, but nothing happens (even error info) with the following conversion...
import dicom2nifti
dicom2nifti.settings.set_gdcmconv_path('C:/Program Files/GDCM 3.0/bin/gdcmconv.exe')
dicom2nifti.convert_directory('M0_1', 'M0_1.nii.gz')
The error occurs when trying other methods....
import dicom2nifti
dicom2nifti.settings.set_gdcmconv_path('C:/Program Files/GDCM 3.0/bin/gdcmconv.exe')
dicom2nifti.dicom_series_to_nifti('M0_1', 'M0_1.nii.gz')
Error Log:
Traceback (most recent call last):
File ".\test.py", line 5, in <module>
dicom2nifti.dicom_series_to_nifti('M0_1', 'M0_1.nii.gz')
File "D:\Anaconda3\envs\pydicom\lib\site-packages\dicom2nifti\convert_dicom.py", line 78, in dicom_series_to_nifti
return dicom_array_to_nifti(dicom_input, output_file, reorient_nifti)
File "D:\Anaconda3\envs\pydicom\lib\site-packages\dicom2nifti\convert_dicom.py", line 112, in dicom_array_to_nifti
if not are_imaging_dicoms(dicom_list):
File "D:\Anaconda3\envs\pydicom\lib\site-packages\dicom2nifti\convert_dicom.py", line 151, in are_imaging_dicoms
if common.is_philips(dicom_input):
File "D:\Anaconda3\envs\pydicom\lib\site-packages\dicom2nifti\common.py", line 102, in is_philips
header = dicom_input[0]
IndexError: list index out of range
File structure:
M0_1
|----IM-0001-0001.dcm
|----IM-0001-0002.dcm
........
|----IM-0001-000299.dcm
|----IM-0001-000300.dcm
Environment:
windows10, python: 3.6, dicom2nifti2.3.0
Where am I doing wrong?
Or is there any other way to convert it?
Thanks in advance!
I haven't used dicom2nifti, but you can convert DICOM to Nifti using SimpleITK.
Here's the code that ought to do the job:
import SimpleITK as sitk
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames('M0_1')
reader.SetFileNames(dicom_names)
image = reader.Execute()
# Added a call to PermuteAxes to change the axes of the data
image = sitk.PermuteAxes(image, [2, 1, 0])
sitk.WriteImage(image, 'M0_1.nii.gz')
You can learn more about SimpleITK here: https://simpleitk.readthedocs.io/
UPDATE: I added a call to SimpleITK's PermuteAxes to change the axis order from X-Y-Z to Z-Y-X.

Error loading image in .mat format in Python

I am trying to load an matlab image in .mat format in python using scipy. it give an error. However, when I load in matlab it shows me exactly what it looks like. How can I load the .mat image in python?
Traceback (most recent call last):
File "<ipython-input-28-d42e90ca2d13>", line 1, in <module>
mat_dict = loadmat('D:/Dataset/Multi-resolution_data/Visual/High/1/image100_256.mat');
File "d:\python\python37\lib\site-packages\scipy\io\matlab\mio.py", line 217, in loadmat
MR, _ = mat_reader_factory(f, **kwargs)
File "d:\python\python37\lib\site-packages\scipy\io\matlab\mio.py", line 78, in mat_reader_factory
raise NotImplementedError('Please use HDF reader for matlab v7.3 files')
NotImplementedError: Please use HDF reader for matlab v7.3 files```
```im= load('D:/Dataset/Multi-resolution_data/Visual/High/1/image100_256.mat')
output is 256x256x11```

Overwriting DICOMDIR file with pydicom

I am editing the meta data of multiple dicom images, divided between dicomdirs. I have successfully loaded the dicomdir, traversed it to find the images, edited their meta data and overwritten the original dicom files.
I then successfully overwrite the dicomdir file itself but when I try to open it (for example with Aeskulap) it gives an error message which says "No study or bad DICOMDIR".
When I try to rerun my code I get the following error messages:
Traceback (most recent call last):
File "dicom_run.py", line 28, in <module>
dicom_dir = read_dicomdir(list_files[0])
File "/home/user/anaconda3/lib/python3.7/site-packages/pydicom
/filereader.py", line 883, in read_dicomdir
ds = dcmread(filename)
File "/home/user/anaconda3/lib/python3.7/site-packages/pydicom
/filereader.py", line 850, in dcmread
force=force, specific_tags=specific_tags)
File "/home/user/anaconda3/lib/python3.7/site-packages/pydicom
/filereader.py", line 741, in read_partial
is_implicit_VR, is_little_endian)
File "/home/user/anaconda3/lib/python3.7/site-packages/pydicom
/dicomdir.py", line 57, in __init__
self.parse_records()
File "/home/user/anaconda3/lib/python3.7/site-packages/pydicom
/dicomdir.py", line 95, in parse_records
child = map_offset_to_record[child_offset]
KeyError: 504
When I access the individual dicom files within the directory they load just fine so the problem is how I'm overwriting the dicomdir.
I do so using the following code
import pydicom
from pydicom.filereader import read_dicomdir
# Load dicomdir
dicom_dir = read_dicomdir(<path_to_dicomdir>)
# Here I just traverse the dicom_dir object
# as is outlined here:
# https://pydicom.github.io/pydicom/stable/auto_examples/input_output/plot_read_dicom_directory.html
# Then I (successfully) overwrite the dicomdir with
dicom_dir.save_as(<path_to_dicomdir>)
I have also tried to use the write_file and write_dataset functions as detailed here:
https://pydicom.github.io/pydicom/stable/api_ref.html#module-pydicom.filewriter
again unsuccessfully. I have a backup of the original dicomdir file and when I replace that everything works fine again (and the meta data of each image has been edited). I'm completely lost here.
Edit:
https://github.com/pydicom/pydicom/issues/918
I stumbled upon this. Guess I'll have to do it another way.
I used dcmmkdir and wrote a small bash script that entered all the folders and ran dcmmkdir +r which successfully overwrote the dicomdir files.

Cannot determine type of file

Hi i have just started learning image processing using python.
When i tried to open an image that i downloaded from the net, I keep getting this error and I have no idea about how to resolve it. Can anyone please help me with this?
>>> dna=mahotas.imread('dna.jpeg')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\mahotas\io\freeimage.py", line 773, in imread
img = read(filename)
File "C:\Python27\lib\site-packages\mahotas\io\freeimage.py", line 444, in read
bitmap = _read_bitmap(filename, flags)
File "C:\Python27\lib\site-packages\mahotas\io\freeimage.py", line 490, in _read_bitmap
'mahotas.freeimage: cannot determine type of file %s' % filename)
ValueError: mahotas.freeimage: cannot determine type of file dna.jpeg
Hello this looks like a pretty old thread but I found it recently because I had the same problem.
I think that the error message is misleading because it implies that the type of file is incorrect.
I fixed the problem by including the full path to the image file. For example, it could look something like:
dna = mahotas.imread('C:\Documents\dna.jpeg')

dxf file parsing with dxfgrabber library in the python

I want to parse dxf file for obtain objects (line, point, text and so on) with dxfgrabber library.
The code is as below
#!/usr/bin/env python
import dxfgrabber
dxf = dxfgrabber.readfile("1.dxf")
print ("DXF version : {}".format(dxf.dxfversion))
But it gets some error...
Traceback (most recent call last):
File "parsing.py", line 6, in <module>
dxf = dxfgrabber.readfile("1.dxf")
File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/__init__.py", line 43, in readfile
with io.open(filename, encoding=get_encoding()) as fp:
File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/__init__.py", line 39, in get_encoding
info = dxfinfo(fp)
File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/tags.py", line 96, in dxfinfo
tag = next(tagreader)
File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/tags.py", line 52, in __next__
return next_tag()
File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/tags.py", line 45, in next_tag
raise StopIteration()
StopIteration
The simple 1.dxf file only contain line.
file link is https://docs.google.com/file/d/0BySHG7k180kETlQ2UnRxQmxoUk0/edit?usp=sharing
Is this bug of dxfgrabber library?
Is there any good library for parsing dxf file in the python?
I am using dxfgrabber 0.4 and python 2.7.3.
I contacted the developer and he says that in current version 0.5.1 make line 49 of __init__.py the following: with io.open(filename) as fp:.
Then it works (io was missing).
He will make this correction official in version 0.5.2 soon.
You can only read dxf made in AutoCAD format!
Try "DraftSight" which is a free AutoCAD clone which exports dxf quite well. Try dxf R12 format.
This will solve your problems.

Categories