Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have 10 files. 1 file contains 50+ dicoms. I'm using a loop (for) to pop up array of all the dicoms in a file at once. is it possible to output an array for all the dicoms in 10 files at once? please help me

i list files using the os library. ID1 to ID10. then to read one file i use this script

<for name in ['ID1',]:
   for dicom in os.listdir("drive/MyDrive/Google Collab/Data/ID1')
     a = dcmread("drive/MyDrive/Google Collab/Data/ID1/" + dicom)


print(sum(a.pixel_array))

What I have tried:

i still cant find the script. right now i just copy paste the script for 1 file and use it for another 9 file..is there a script that can make it easier or how to make the script into a funtion?
Posted
Updated 29-Jul-23 10:25am
v3

Make it a function or method that you pass the file path to.
Then call that for each file.
 
Share this answer
 
Comments
mz13 29-Jul-23 13:36pm    
hi, thankyou for answering
how do i transform this into a function?
i list files using the os library. ID1 to ID10. then to read one file i use this script

for name in ['ID1',]:
for dicom in os.listdir("drive/MyDrive/Google Collab/Data/ID1')
a = dcmread("drive/MyDrive/Google Collab/Data/ID1/" + dicom)

print(sum(a.pixel_array))
OriginalGriff 29-Jul-23 16:46pm    
Oh come on - you know the language better than that: https://www.w3schools.com/python/python_functions.asp

If you don't, then you really, really aren't going to get far until you sit down and learn it ...
Quote:
i still cant find the script.

What about learning to program and adaot existing script or create one ?
Try 2 nested loops. It is generic programming technique.
Show your actual script.
 
Share this answer
 
Comments
mz13 29-Jul-23 13:15pm    
hi, thankyou for answering.
i list files using the os library. ID1 to ID10. then to read one file i use this script

for name in ['ID1',]:
for dicom in os.listdir("drive/MyDrive/Google Collab/Data......."):
a = dcmread("drive/MyDrive/Google Collab......" + dicom)

print(sum(a.pixel_array))
Patrice T 29-Jul-23 13:29pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900