def get_raw_data(self): """Get the pixel intensities (i.e. read the image and return as a flex array of integers.)""" from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert len(self.get_detector()) == 1 image_pedestal = 40 panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVADSCSN.open_file(self._image_file, "rb") f.read(self._header_size) if self._header_dictionary["BYTE_ORDER"] == "big_endian": big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) # apply image pedestal, will result in *negative pixel values* raw_data -= image_pedestal image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert(len(self.get_detector()) == 1) panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVADSC.open_file(self._image_file, 'rb') f.read(self._header_size) if self._header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex f = self.open_file(self._image_file, 'rb') f.read(self._header_size) if self._header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(512 * 512)) else: raw_data = read_uint16_bs(streambuf(f), int(512 * 512)) image_size = (512, 512) raw_data.reshape(flex.grid(image_size[1], image_size[0])) # split into separate panels self._raw_data = [] d = self.get_detector() for panel in d: xmin, ymin, xmax, ymax = self.coords[panel.get_name()] self._raw_data.append(raw_data[ymin:ymax, xmin:xmax]) return tuple(self._raw_data)
def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert (len(self.get_detector()) == 1) panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVNOIR.open_file(self._image_file, 'rb') f.read(self._header_size) if self._header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def read_smv_image(image_file): from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex header_size, header_dictionary = get_smv_header(image_file) f = open(image_file, 'rb') f.read(header_size) if header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False image_size = (int(header_dictionary['SIZE1']), int(header_dictionary['SIZE2'])) if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(image_size[0] * image_size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(image_size[0] * image_size[1])) raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex f = self.open_file(self._image_file, 'rb') f.read(self._header_size) nx = int(self._header_dictionary['SIZE1']) # number of pixels ny = int(self._header_dictionary['SIZE2']) # number of pixels if self._header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(nx * ny)) else: raw_data = read_uint16_bs(streambuf(f), int(nx * ny)) # note that x and y are reversed here raw_data.reshape(flex.grid(ny, nx)) self._raw_data = raw_data return self._raw_data
def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex f = self.open_file(self._image_file, 'rb') header_size = int(self.header_dict['HDRBLKS']) * 512 f.read(header_size) # 16 bits per pixel assert int(self.header_dict['NPIXELB'].split()[0]) == 2 nrows = int(self.header_dict['NROWS'].split()[0]) ncols = int(self.header_dict['NCOLS'].split()[0]) if is_big_endian(): raw_data = read_uint16_bs(streambuf(f), nrows * ncols) else: raw_data = read_uint16(streambuf(f), nrows * ncols) image_size = (nrows, ncols) raw_data.reshape(flex.grid(image_size[0], image_size[1])) return raw_data
def get_raw_data(self): """Get the pixel intensities (i.e. read the image and return as a flex array of integers.)""" from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert len(self.get_detector()) == 1 image_pedestal = int(self._header_dictionary["IMAGE_PEDESTAL"]) panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVADSCSN.open_file(self._image_file, "rb") f.read(self._header_size) if self._header_dictionary["BYTE_ORDER"] == "big_endian": big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) # apply image pedestal, will result in *negative pixel values* raw_data -= image_pedestal image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def read_smv_image(image_file): from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex header_size, header_dictionary = get_smv_header(image_file) with open(image_file, "rb") as f: f.seek(header_size) if header_dictionary["BYTE_ORDER"] == "big_endian": big_endian = True else: big_endian = False image_size = (int(header_dictionary["SIZE1"]), int(header_dictionary["SIZE2"])) if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(image_size[0] * image_size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(image_size[0] * image_size[1])) raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def get_raw_data(self, index): from boost.python import streambuf from scitbx.array_family import flex # is this image a type we can read? assert self._data_type in ["h", "f", "B", "l", "b", "H", "I", "d"] with FormatGatanDM4.open_file(self._image_file, "rb") as f: f.seek(self._data_offset) skip_bytes = index * self._image_num_elements * self._data_size f.seek(skip_bytes, whence=1) if self._data_type == "f": from dxtbx import read_float32 raw_data = read_float32(streambuf(f), self._image_num_elements) elif self._data_type == "B": from dxtbx import read_uint8 raw_data = read_uint8(streambuf(f), self._image_num_elements) elif self._data_type == "h": from dxtbx import read_int16 raw_data = read_int16(streambuf(f), self._image_num_elements) elif self._data_type == "H": from dxtbx import read_uint16 raw_data = read_uint16(streambuf(f), self._image_num_elements) elif self._data_type == "l": from dxtbx import read_int32 raw_data = read_int32(streambuf(f), self._image_num_elements) elif self._data_type == "I": from dxtbx import read_uint32 raw_data = read_uint32(streambuf(f), self._image_num_elements) # no C++ reader for remaining types (should be unusual anyway) else: vals = struct.unpack( self._byteord + self._data_type * self._image_num_elements, f.read(self._data_size * self._image_num_elements), ) if self._data_type == "d": raw_data = flex.double(vals) if self._data_type in ["b", "?"]: raw_data = flex.int(vals) raw_data.reshape(flex.grid(self._image_size[1], self._image_size[0])) return raw_data
def get_raw_data(self): """Get the pixel intensities (i.e. read the image and return as a flex array of integers.)""" # currently have no non-little-endian machines... assert len(self.get_detector()) == 1 image_size = self.get_detector()[0].get_image_size() with self.open_file(self._image_file) as fh: fh.seek(self._header_size) raw_data = read_uint16(streambuf(fh), int(image_size[0] * image_size[1])) raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def read_tiff_image(image_file): # currently have no non-little-endian machines... from boost.python import streambuf from dxtbx import read_uint16 from scitbx.array_family import flex width, height, depth, order, header_bytes = get_tiff_header(image_file) image_size = (width, height) header_size = 4096 f = open(image_file) f.read(header_size) raw_data = read_uint16(streambuf(f), int(image_size[0] * image_size[1])) raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def get_raw_data(self, index): from boost.python import streambuf from scitbx.array_family import flex # is this image a type we can read? assert self._data_type in ['h', 'f', 'B', 'l', 'b', 'H', 'I', 'd'] with FormatGatanDM4.open_file(self._image_file, 'rb') as f: f.seek(self._data_offset) skip_bytes = index * self._image_num_elements * self._data_size f.seek(skip_bytes, whence=1) if self._data_type == 'f': from dxtbx import read_float32 raw_data = read_float32(streambuf(f), self._image_num_elements) elif self._data_type == 'B': from dxtbx import read_uint8 raw_data = read_uint8(streambuf(f), self._image_num_elements) elif self._data_type == 'h': from dxtbx import read_int16 raw_data = read_int16(streambuf(f), self._image_num_elements) elif self._data_type == 'H': from dxtbx import read_uint16 raw_data = read_uint16(streambuf(f), self._image_num_elements) elif self._data_type == 'l': from dxtbx import read_int32 raw_data = read_int32(streambuf(f), self._image_num_elements) elif self._data_type == 'I': from dxtbx import read_uint32 raw_data = read_uint32(streambuf(f), self._image_num_elements) # no C++ reader for remaining types (should be unusual anyway) else: vals = struct.unpack( self._byteord + self._data_type * self._image_num_elements, f.read(self._data_size * self._image_num_elements)) if self._data_type == 'd': raw_data = flex.double(vals) if self._data_type in ['b', '?']: raw_data = flex.int(vals) raw_data.reshape(flex.grid(self._image_size[1], self._image_size[0])) return raw_data
def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' # currently have no non-little-endian machines... from boost.python import streambuf from dxtbx import read_uint16 from scitbx.array_family import flex assert (len(self.get_detector()) == 1) size = self.get_detector()[0].get_image_size() f = FormatSMV.open_file(self._image_file) f.read(self._header_size) raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) image_size = self.get_detector()[0].get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' # currently have no non-little-endian machines... from boost.python import streambuf from dxtbx import read_uint16 from scitbx.array_family import flex assert(len(self.get_detector()) == 1) size = self.get_detector()[0].get_image_size() f = FormatSMV.open_file(self._image_file) f.read(self._header_size) raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) image_size = self.get_detector()[0].get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def get_raw_data(self): """Get the pixel intensities (i.e. read the image and return as a flex array of integers.)""" # currently have no non-little-endian machines... assert self._tiff_byte_order == FormatTIFF.LITTLE_ENDIAN bias = int(round(self._get_bruker_bias())) assert len(self.get_detector()) == 1 size = self.get_detector()[0].get_image_size() f = FormatTIFF.open_file(self._image_file) f.read(self._header_size) raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) - bias image_size = self.get_detector()[0].get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def get_raw_data(self): """Get the pixel intensities (i.e. read the image and return as a flex array of integers.)""" from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert len(self.get_detector()) == 1 image_pedestal = 1 try: image_pedestal = float(self._header_dictionary["ADC_OFFSET"]) except KeyError: pass panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVJHSim.open_file(self._image_file, "rb") f.read(self._header_size) if self._header_dictionary["BYTE_ORDER"] == "big_endian": big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) # apply image pedestal, will result in *negative pixel values* # this is a horrible idea since raw_data is unsigned # see all instances of image_pedestal in dxtbx raw_data -= int(image_pedestal) image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data