title: Decompress nifti medical image in gz format using python
body: <p>I want to decompress a butch of nii.gz files in python so that they could be processed in sitk later on. When I decompress a single file manually by right-clicking the file and choosing 'Extract..', this file is then correctly interpreted by sitk (I do sitk.ReadImage(unzipped)). But when I try to decompress it in python using following code:</p>
  
  <pre><code>with gzip.open(segmentation_zipped, "rb") as f:
      bindata = f.read()
  segmentation_unzipped = os.path.join(segmentation_zipped.replace(".gz", ""))
  with gzip.open(segmentation_unzipped, "wb") as f:
      f.write(bindata)
  </code></pre>
  
  <p>I get error when sitk tries to read the file:
  <em>RuntimeError: Exception thrown in SimpleITK ReadImage: C:\d\VS14-Win64-pkg\SimpleITK\Code\IO\src\sitkImageReaderBase.cxx:82:
  sitk::ERROR: Unable to determine ImageIO reader for "E:\BraTS19_2013_10_1_seg.nii"</em></p>
  
  <p>Also when trying to do it a little differently:</p>
  
  <pre><code>input = gzip.GzipFile(segmentation_zipped, 'rb')
  s = input.read()
  input.close()
  
  segmentation_unzipped = os.path.join(segmentation_zipped.replace(".gz", ""))
  output = open(segmentation_unzipped, 'wb')
  output.write(s)
  output.close()
  </code></pre>
  
  <p>I get:
  <em>RuntimeError: Exception thrown in SimpleITK ReadImage: C:\d\VS14-Win64-pkg\SimpleITK-build\ITK\Modules\IO\PNG\src\itkPNGImageIO.cxx:101:
  itk::ERROR: PNGImageIO(0000022E3AF2C0C0): PNGImageIO failed to read header for file: 
  Reason: fread read only 0 instead of 8</em></p>
  
  <p>can anyone help?</p>