def _get_raw_image_data(self, image_group_number, channel_offset, height, width): """ Reads the raw bytes and the timestamp of an image. :param image_group_number: groups are made of images with the same time index, field of view and z-level. :type image_group_number: int :param channel_offset: the offset in the array where the bytes for this image are found. :type channel_offset: int :return: (int, array.array()) or None """ chunk = self._label_map[six.b("ImageDataSeq|%d!" % image_group_number)] data = read_chunk(self._file_handle, chunk) # All images in the same image group share the same timestamp! So if you have complicated image data, # your timestamps may not be entirely accurate. Practically speaking though, they'll only be off by a few # seconds unless you're doing something super weird. timestamp = struct.unpack("d", data[:8])[0] image_group_data = array.array("H", data) image_data_start = 4 + channel_offset # The images for the various channels are interleaved within the same array. For example, the second image # of a four image group will be composed of bytes 2, 6, 10, etc. If you understand why someone would design # a data structure that way, please send the author of this library a message. image_data = np.reshape(image_group_data[image_data_start::len(self._metadata.channels)], (height, width)) # Skip images that are all zeros! This is important, since NIS Elements creates blank "gap" images if you # don't have the same number of images each cycle. We discovered this because we only took GFP images every # other cycle to reduce phototoxicity, but NIS Elements still allocated memory as if we were going to take # them every cycle. if np.any(image_data): return timestamp, Image(image_data) raise NoImageError
def _parse_metadata(self): """ Reads all metadata. """ metadata_dict = {} self._label_map = self._build_label_map() for label in self._label_map.keys(): if label.endswith(six.b("LV!")) or six.b("LV|") in label: data = read_chunk(self._fh, self._label_map[label]) stop = label.index(six.b("LV")) metadata_dict[label[:stop]] = self._read_metadata(data, 1) height = metadata_dict[six.b('ImageAttributes')][six.b('SLxImageAttributes')][six.b('uiHeight')] width = metadata_dict[six.b('ImageAttributes')][six.b('SLxImageAttributes')][six.b('uiWidth')] channels = self._parse_channels(metadata_dict) date = self._parse_date(metadata_dict) fields_of_view = self._parse_fields_of_view(metadata_dict) frames = self._parse_frames(metadata_dict) z_levels = self._parse_z_levels(metadata_dict) total_images_per_channel = self._parse_total_images_per_channel(metadata_dict) self._metadata = Metadata(height, width, channels, date, fields_of_view, frames, z_levels, total_images_per_channel)
def _parse_metadata(self): """ Reads all metadata. """ metadata_dict = {} self._label_map = self._build_label_map() for label in self._label_map.keys(): if label.endswith(six.b("LV!")) or six.b("LV|") in label: data = read_chunk(self._fh, self._label_map[label]) stop = label.index(six.b("LV")) metadata_dict[label[:stop]] = self._read_metadata(data, 1) height = metadata_dict[six.b("ImageAttributes")][six.b("SLxImageAttributes")][six.b("uiHeight")] width = metadata_dict[six.b("ImageAttributes")][six.b("SLxImageAttributes")][six.b("uiWidth")] channels = self._parse_channels(metadata_dict) date = self._parse_date(metadata_dict) fields_of_view = self._parse_fields_of_view(metadata_dict) frames = self._parse_frames(metadata_dict) z_levels = self._parse_z_levels(metadata_dict) total_images_per_channel = self._parse_total_images_per_channel(metadata_dict) self._metadata = Metadata( height, width, channels, date, fields_of_view, frames, z_levels, total_images_per_channel )
def image_calibration(self): return read_metadata(read_chunk(self._fh, self._label_map.image_calibration), 1)
def image_metadata_sequence(self): return read_metadata(read_chunk(self._fh, self._label_map.image_metadata_sequence), 1)
def image_text_info(self): return read_metadata(read_chunk(self._fh, self._label_map.image_text_info), 1)
def image_metadata(self): if self._label_map.image_metadata: return read_metadata(read_chunk(self._fh, self._label_map.image_metadata), 1)
def custom_data(self): return xmltodict.parse(read_chunk(self._fh, self._label_map.custom_data))
def lut_data(self): return xmltodict.parse(read_chunk(self._fh, self._label_map.lut_data))
def grabber_settings(self): return xmltodict.parse(read_chunk(self._fh, self._label_map.grabber_settings))
def roi_metadata(self): return read_metadata(read_chunk(self._fh, self._label_map.roi_metadata), 1)
def image_attributes(self): return read_metadata(read_chunk(self._fh, self._label_map.image_attributes), 1)
def app_info(self): return xmltodict.parse(read_chunk(self._fh, self._label_map.app_info))