def imread_qt(filename):
 qtimg = QImage()
 if (not qtimg.load(filename)):
  raise IOError(('Unable to load file %s' % filename))
 if (qtimg.depth() == 1):
  raise IOError('1-bit images currently not supported')
 arrayptr = qtimg.bits()
 bytes_per_pixel = (qtimg.depth() // 8)
 pixels_per_line = (qtimg.bytesPerLine() // bytes_per_pixel)
 img_size = ((pixels_per_line * qtimg.height()) * bytes_per_pixel)
 arrayptr.setsize(img_size)
 img = np.array(arrayptr)
 if (bytes_per_pixel > 1):
  img = img.reshape((qtimg.height(), pixels_per_line, bytes_per_pixel))
  img = img[:, :qtimg.width(), :]
 else:
  img = img.reshape((qtimg.height(), pixels_per_line))
  img = img[:, :qtimg.width()]
 if ((bytes_per_pixel == 4) and (not qtimg.hasAlphaChannel())):
  img = img[:, :, 2::(-1)]
 elif (bytes_per_pixel == 4):
  img[:, :, 0:3] = img[:, :, 2::(-1)]
 return img

def imread_qt ( filename ) : qtimg = QImage ( ) if ( not qtimg . load ( filename ) ) : raise IOError ( ( 'Unable to load file %s' % filename ) ) if ( qtimg . depth ( ) == 1 ) : raise IOError ( '1-bit images currently not supported' ) arrayptr = qtimg . bits ( ) bytes_per_pixel = ( qtimg . depth ( ) // 8 ) pixels_per_line = ( qtimg . bytesPerLine ( ) // bytes_per_pixel ) img_size = ( ( pixels_per_line * qtimg . height ( ) ) * bytes_per_pixel ) arrayptr . setsize ( img_size ) img = np . array ( arrayptr ) if ( bytes_per_pixel > 1 ) : img = img . reshape ( ( qtimg . height ( ) , pixels_per_line , bytes_per_pixel ) ) img = img [ : , : qtimg . width ( ) , : ] else : img = img . reshape ( ( qtimg . height ( ) , pixels_per_line ) ) img = img [ : , : qtimg . width ( ) ] if ( ( bytes_per_pixel == 4 ) and ( not qtimg . hasAlphaChannel ( ) ) ) : img = img [ : , : , 2 : : ( - 1 ) ] elif ( bytes_per_pixel == 4 ) : img [ : , : , 0 : 3 ] = img [ : , : , 2 : : ( - 1 ) ] return img
read an image using qts qimage .