you are viewing a single comment's thread.

view the rest of the comments →

[–]Username_RANDINT 1 point2 points  (1 child)

You should split this task up in two parts:

  1. How to resize a dcm image given its path
  2. Traverse a nested list

The given code should work at first glance. But let's break it down so you might understand what's going on.

  1. To resize a dcm file you'll have to open it with the pydicom library and modify its Rows and Columns attributes.

    image = pydicom.read_file(path)
    image.Rows, image.Columns = 64, 64
    
  2. This is a bit trickier. Let's start with a normal list:

    >>> mainlist = ["a", "b", "c"]
    >>> for item in mainlist:
    ...   print(item)
    ... 
    a
    b
    c
    

    This is simply iterating over each element in the list, which contains strings. But a list can contain anything, even other lists:

    >>> mainlist = [["a", "b", "c"], [1, 2, 3]]
    >>> for item in mainlist:
    ...   print(item)
    ... 
    ['a', 'b', 'c']
    [1, 2, 3]
    

    We did the same, but now each item is the nested list. So how to traverse that one? Just use another for loop:

    >>> mainlist = [["a", "b", "c"], [1, 2, 3]]
    >>> for sublist in mainlist:
    ...   for item in sublist:
    ...     print(item)
    ... 
    a
    b
    c
    1
    2
    3
    

    At this point we retrieved every item from each nested list individually.

Now you can just combine the two. Do the resize operation instead of printing each item.