Esempio n. 1
0
    def chooseStack_slot(self, fnameToChoose=False):
        """
        Choose the stack to transform
        can optionally load a specific file name (used for de-bugging)
        """
        if fnameToChoose==False:         
            fileFilter="Images (*.mhd *.mha)"
            fnameToChoose = QtGui.QFileDialog.getOpenFileName(self, 'Choose stack', lasHelp.readPreference('lastLoadDir'), fileFilter)
            fnameToChoose = str(fnameToChoose)


        if os.path.exists(fnameToChoose):
            self.inputImagePath = fnameToChoose
        else:
            self.inputImagePath = ''
            #TODO: make an alert box for this case
            print "that file does not exits"
        
        self.checkIfReadyToRun()
        lasHelp.preferenceWriter('lastLoadDir', lasHelp.stripTrailingFileFromPath(fnameToChoose))
        self.stackName_label.setText(fnameToChoose.split(os.path.sep)[-1])
Esempio n. 2
0
    def chooseTransform_slot(self, fnameToChoose=False):
        """
        Choose the transform file to use
        can optionally load a specific file name (used for de-bugging)
        """
        if fnameToChoose == False:
            fileFilter = "Images (*.txt)"
            fnameToChoose = QtGui.QFileDialog.getOpenFileName(
                self, 'Choose transform',
                lasHelp.readPreference('lastLoadDir'), fileFilter)
            fnameToChoose = str(fnameToChoose)

        if os.path.exists(fnameToChoose):
            self.transformPath = fnameToChoose
        else:
            self.transformPath = ''
            #TODO: make an alert box for this case
            print("that file does not exits")

        self.checkIfReadyToRun()
        lasHelp.preferenceWriter(
            'lastLoadDir', lasHelp.stripTrailingFileFromPath(fnameToChoose))
        self.transformName_label.setText(fnameToChoose.split(os.path.sep)[-1])
Esempio n. 3
0
def mhd_read_raw_file(fname,header):
  """
  Raw .raw file associated with the MHD header file
  CAUTION: this may not adhere to MHD specs! Report bugs to author.
  """

  if header.has_key('headersize'):
    if header['headersize']>0:
      print "\n\n **MHD reader can not currently cope with header information in .raw file. Contact the author** \n\n"
      return False

  #Set the endian type correctly
  if header.has_key('byteorder'):
    if header['byteorder'].lower == 'true' :
      endian = '>' #big endian
    else:
      endian = '<' #little endian
  else:
    endian = '<' #little endian


  #Set the data type correctly 
  if header.has_key('datatype'):
    datatype = header['datatype'].lower()

    if datatype == 'float':
      formatType = 'f'
    elif datatype == 'double':
      formatType = 'd'
    elif datatype == 'long':
      formatType = 'l'
    elif datatype == 'ulong':
      formatType = 'L'
    elif datatype == 'char':
      formatType = 'c'
    elif datatype == 'uchar':
      formatType = 'B'
    elif datatype == 'short':
      formatType = 'h'      
    elif datatype == 'ushort':
      formatType = 'H'      
    elif datatype == 'int':
      formatType = 'i'      
    elif datatype == 'uint':
      formatType = 'I'
    else:
      formatType = False

  else:
      formatType = False

  if formatType == False:
    print "\nCan not find data format type in MHD file. **CONTACT AUTHOR**\n"
    return False


  pathToFile = lasHelp.stripTrailingFileFromPath(fname)
  rawFname = os.path.join(pathToFile,header['elementdatafile'])
  with  open(rawFname,'rb') as fid:
    data = fid.read()
    
  dimSize = header['dimsize']
  #from: http://stackoverflow.com/questions/26542345/reading-data-from-a-16-bit-unsigned-big-endian-raw-image-file-in-python
  fmt = endian + str(int(np.prod(dimSize))) + formatType
  pix = np.asarray(struct.unpack(fmt, data))
  
  return pix.reshape((dimSize[2],dimSize[1],dimSize[0])).swapaxes(1,2)