Error loading image in .mat format in Python - 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```

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.

How to Display .raw Dataset?

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.

Python executable cannot read file

Given below is the code that I am using to read values form a file
import linecache
line_number=line_number+1
linecache.getline("write.txt", line_number)
I am using py2exe to convert the file into an executable. The problem is after conversion to exe it cannot read the file.
The error message is:
Could not convert string to a float
As suggested in the comment the full error trace is:
Traceback (most recent call last):
File "logic.py", line 437, in <module>
File "logic.py", line 224, in readdata
ValueError: could not convert string to float:
Where am I going wrong?

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')

Scipy.loadmat() ---- SystemError: ../Objects/stringobject.c:3899: bad argument to internal function

I'm trying to load a .mat file into python that is quite large ( >75MB) and I am getting the following error. Can this be helped?
Traceback (most recent call last):
File "prop_keys.py", line 34, in <module>
prop_d = scipy.io.loadmat(prop)
File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio.py", line 175, in loadmat
matfile_dict = MR.get_variables(variable_names)
File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 272, in get_variables
hdr, next_position = self.read_var_header()
File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 224, in read_var_header
stream = BytesIO(dcor.decompress(data))
SystemError: ../Objects/stringobject.c:3899: bad argument to internal function
As noted here: http://projects.scipy.org/scipy/ticket/1894
The file contains compressed data which blows up to 1.1GB when uncompressed.
The error message is a symptom of your machine not having enough free memory to store this data. In addition to this, the latter part of the file seems also corrupted and cannot be correctly loaded by Matlab either.
(Scipy's mat-file loading routines actually require 2x memory if the data is compressed; however, this will be fixed in Scipy 0.13.0.)

Categories