New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extracting ROI pixel Value from a directory #622
Comments
So you should get a list of datasets here. What do you get instead? |
i get an Error :(InvalidDicomError: File is missing DICOM File Meta Information header or the 'DICM' prefix is missing from the header. Use force=True to force reading.) i tried to use force=True but it does not work either . |
Well, looks like you have a non-DICOM file in your folder. Also, you did not filter out subdirectories (just in case there exist some). |
i Printed the files so i get all the files name in the directory and there is no subdirectories in the Folder . So if i get the right files , can i read and extract the Pixel value(4 Positions) from all the files or must i do it manually ? Thanks a lot for your Help :) |
The ending of the file name does not matter. Just try to check where the problem occurs: for filename in os.listdir(dirname):
try:
pydicom.dcmread(os.path.join(dirname, filename))
except InvalidDicomError:
print(filename) |
Ok, sorry, you have to import that: from pydicom.errors import InvalidDicomError |
Ah okay, i get now no Error and the list of all the files ! |
Hm, that means that you can't read these files at all - you said that you tried this with |
You wrote that you succeeded with one file - how did you do that? Or was that another file? |
I just noticed that: |
i am using Python 2.7 |
The usual CPython? I'm just curious how that works at all with the backslashes... Or maybe your environment converts it? Anyway, to be completely sure, use |
Also, you tried it with the last file, is it the same with the first one? E.g. |
So i used print(os.path.join(dirname, filename)) and i get C:\Python27\DICOM\ST000000\SE000013\MR000193 in the case of the one file ,it is not a problem wich one is choosen, the first one will be also okay |
That is strange. You mean you get the exception for each file if call |
Hm, I don't see the list of the filenames in the output of [7] - I guess you just omitted them? |
If not, that means that it works... |
yes it works |
So, what changed? You got it to work? |
i can see all the filenames now with print filename. Do you have an idea how can i go further ? Thank you! |
I admit I'm at a loss here - I don't understand the difference between the two calls (e.g. in the loop and outside). Also, I still don't understand why your paths work with backslashes, but maybe that's an IPython thing - I haven't used it. |
To be completely sure: for filename in os.listdir(dirname):
filepath = os.path.join(dirname, filename)
print 'Reading', filepath
try:
pydicom.dcmread(filepath)
print 'Succeeded'
except InvalidDicomError:
print('Failed') gives you 'Failed' for all files, right? |
i have the IPython , without the backslashes nothing works. So like you said i moved the DICOM directory from the Python installation directory , and now it works for having filesname list without the InvalidDicomError thing , hmm so weird ! |
So it does work now correctly? |
Yes - now your original code that uses the list comprehension should work (though it may be better to use a generator expression instead to avoid getting all datasets in memory at once). |
okay, thanks a lot . |
Well, the easiest is probably to just use a for loop as you did and do the processing in the loop to get it running. |
so only with the for loop i can execute operations on the entire directory ! that will be great ! Thanks a lot fo your Help !! |
You are welcome - have fun! |
Hi Everyone,
i have a directory with 189 DICOM data and i want to extract all the pixel Value in a specific ROI from all the DICOM Images , i used to do this for one image and that´s working.
i tried to open the directory and to switch it into numpy Array but i couldnt have any results.
This how looks my first try:
import os
import pydicom
import matplotlib.pyplot as plt
import numpy as np
dirname = 'C:\Python27\DICOM\ST000000\SE000013/'
files = os.listdir(dirname)
ds_list = [pydicom.dcmread(os.path.join(dirname, filename) ) for filename in files]
Thanks !
The text was updated successfully, but these errors were encountered: