class_docstr: Reads a variety of image formats using the bio-formats library.
  
  This reader is Java-based.
class_docstr_tok: ["Reads","a","variety","of","image","formats","using","the","bio-formats","library",".","This","reader","is","Java-based","."]
docstr: Read a single plane from the image file.
  :param c: read from this channel. `None` = read color image if multichannel
      or interleaved RGB.
  :param z: z-stack index
  :param t: time index
  :param series: series for ``.flex`` and similar multi-stack formats
  :param index: if `None`, fall back to ``zct``, otherwise load the indexed frame
  :param rescale: `True` to rescale the intensity scale to 0 and 1; `False` to
            return the raw values native to the file.
  :param xywh: a (x, y, w, h) tuple
  :param wants_max_intensity: if `False`, only return the image; if `True`,
            return a tuple of image and max intensity
  :param channel_names: provide the channel names for the OME metadata
  :param XYWH: a (x, y, w, h) tuple
docstr_tok: ["Read","a","single","plane","from","the","image","file",".",":","param","c",":","read","from","this","channel",".","`","None","`","=","read","color","image","if","multichannel","or","interleaved","RGB",".",":","param","z",":","z-stack","index",":","param","t",":","time","index",":","param","series",":","series","for","``",".flex","``","and","similar","multi-stack","formats",":","param","index",":","if","`","None","`",",","fall","back","to","``","zct","``",",","otherwise","load","the","indexed","frame",":","param","rescale",":","`","True","`","to","rescale","the","intensity","scale","to","0","and","1",";","`","False","`","to","return","the","raw","values","native","to","the","file",".",":","param","xywh",":","a","(","x",",","y",",","w",",","h",")","tuple",":","param","wants_max_intensity",":","if","`","False","`",",","only","return","the","image",";","if","`","True","`",",","return","a","tuple","of","image","and","max","intensity",":","param","channel_names",":","provide","the","channel","names","for","the","OME","metadata",":","param","XYWH",":","a","(","x",",","y",",","w",",","h",")","tuple"]
code: def read(
      self,
      series=None,
      index=None,
      c=None,
      z=0,
      t=0,
      rescale=True,
      xywh=None,
      wants_max_intensity=False,
      channel_names=None,
      XYWH=None,
  ):
      """Read a single plane from the image file.
      :param c: read from this channel. `None` = read color image if multichannel
          or interleaved RGB.
      :param z: z-stack index
      :param t: time index
      :param series: series for ``.flex`` and similar multi-stack formats
      :param index: if `None`, fall back to ``zct``, otherwise load the indexed frame
      :param rescale: `True` to rescale the intensity scale to 0 and 1; `False` to
                return the raw values native to the file.
      :param xywh: a (x, y, w, h) tuple
      :param wants_max_intensity: if `False`, only return the image; if `True`,
                return a tuple of image and max intensity
      :param channel_names: provide the channel names for the OME metadata
      :param XYWH: a (x, y, w, h) tuple
      """
      self._ensure_file_open()
  
      FormatTools = jimport("loci.formats.FormatTools")
      ChannelSeparator = jimport("loci.formats.ChannelSeparator")
      if series is not None:
          self._reader.setSeries(series)
  
      if XYWH is not None:
          assert (
              isinstance(XYWH, tuple) and len(XYWH) == 4
          ), "Invalid XYWH tuple"
          openBytes_func = lambda x: self._reader.openBytes(
              x, XYWH[0], XYWH[1], XYWH[2], XYWH[3]
          )
          width, height = XYWH[2], XYWH[3]
      else:
          openBytes_func = self._reader.openBytes
          width, height = (
              self._reader.getSizeX(),
              self._reader.getSizeY(),
          )
  
      # FIXME instead of np.frombuffer use scyjava.to_python, ideally that wraps memory
      pixel_type = self._reader.getPixelType()
      little_endian = self._reader.isLittleEndian()
      if pixel_type == FormatTools.INT8:
          dtype = np.int8
          scale = 255
      elif pixel_type == FormatTools.UINT8:
          dtype = np.uint8
          scale = 255
      elif pixel_type == FormatTools.UINT16:
          dtype = "<u2" if little_endian else ">u2"
          scale = 65535
      elif pixel_type == FormatTools.INT16:
          dtype = "<i2" if little_endian else ">i2"
          scale = 65535
      elif pixel_type == FormatTools.UINT32:
          dtype = "<u4" if little_endian else ">u4"
          scale = 2**32
      elif pixel_type == FormatTools.INT32:
          dtype = "<i4" if little_endian else ">i4"
          scale = 2**32 - 1
      elif pixel_type == FormatTools.FLOAT:
          dtype = "<f4" if little_endian else ">f4"
          scale = 1
      elif pixel_type == FormatTools.DOUBLE:
          dtype = "<f8" if little_endian else ">f8"
          scale = 1
      max_sample_value = self._reader.getMetadataValue("MaxSampleValue")
      if max_sample_value is not None:
          try:
              scale = scyjava.to_python(max_sample_value)
          except:
              LOGGER.warning(
                  "WARNING: failed to get MaxSampleValue for image. Intensities may be improperly scaled."
              )
      if index is not None:
          image = np.frombuffer(openBytes_func(index), dtype)
          if len(image) / height / width in (3, 4):
              n_channels = int(len(image) / height / width)
              if self._reader.isInterleaved():
                  image.shape = (height, width, n_channels)
              else:
                  image.shape = (n_channels, height, width)
                  image = image.transpose(1, 2, 0)
          else:
              image.shape = (height, width)
      elif self._reader.isRGB() and self._reader.isInterleaved():
          index = self._reader.getIndex(z, 0, t)
          image = np.frombuffer(openBytes_func(index), dtype)
          image.shape = (height, width, self._reader.getSizeC())
          if image.shape[2] > 3:
              image = image[:, :, :3]
      elif c is not None and self._reader.getRGBChannelCount() == 1:
          index = self._reader.getIndex(z, c, t)
          image = np.frombuffer(openBytes_func(index), dtype)
          image.shape = (height, width)
      elif self._reader.getRGBChannelCount() > 1:
          n_planes = self._reader.getRGBChannelCount()
          rdr = ChannelSeparator(self._reader)
          planes = [
              np.frombuffer(
                  (
                      rdr.openBytes(rdr.getIndex(z, i, t))
                      if XYWH is None
                      else rdr.openBytes(
                          rdr.getIndex(z, i, t),
                          XYWH[0],
                          XYWH[1],
                          XYWH[2],
                          XYWH[3],
                      )
                  ),
                  dtype,
              )
              for i in range(n_planes)
          ]
  
          if len(planes) > 3:
              planes = planes[:3]
          elif len(planes) < 3:
              # > 1 and < 3 means must be 2
              # see issue #775
              planes.append(np.zeros(planes[0].shape, planes[0].dtype))
          image = np.dstack(planes)
          image.shape = (height, width, 3)
      elif self._reader.getSizeC() > 1:
          images = [
              np.frombuffer(
                  openBytes_func(self._reader.getIndex(z, i, t)), dtype
              )
              for i in range(self._reader.getSizeC())
          ]
          image = np.dstack(images)
          image.shape = (height, width, self._reader.getSizeC())
          if not channel_names is None:
              metadata = self._reader.getMetadataStore()
              for i in range(self._reader.getSizeC()):
                  index = self._reader.getIndex(z, 0, t)
                  channel_name = metadata.getChannelName(index, i)
                  if channel_name is None:
                      channel_name = metadata.getChannelID(index, i)
                  channel_names.append(channel_name)
      elif self._reader.isIndexed():
          # TODO can we use ChannelFiller, which automatically expands channels if they
          # are "true" color and does nothing if they are "false" (e.g. applied color table)?
          #
          # The image data is indexes into a color lookup-table
          # But sometimes the table is the identity table and just generates
          # a monochrome RGB image
          #
          index = self._reader.getIndex(z, 0, t)
          image = np.frombuffer(openBytes_func(index), dtype)
          lut = None
          if pixel_type in (FormatTools.INT16, FormatTools.UINT16):
              lut = self._reader.get16BitLookupTable()
          else:
              lut = self._reader.get8BitLookupTable()
          if lut is not None:
              lut = np.array([d for d in lut]).transpose()
          image.shape = (height, width)
          if (lut is not None) and not np.all(
              lut == np.arange(lut.shape[0])[:, np.newaxis]
          ):
              image = lut[image, :]
      else:
          index = self._reader.getIndex(z, 0, t)
          image = np.frombuffer(openBytes_func(index), dtype)
          image.shape = (height, width)
  
      if rescale:
          image = image.astype(np.float32) / float(scale)
      if wants_max_intensity:
          return image, scale
      return image
  
file_path: CellProfiler/src/subpackages/core/cellprofiler_core/readers/bioformats_reader.py
imports: import collections
  import itertools
  import logging
  import numpy
  import scyjava
  from ..utilities.image import is_file_url
  from ..utilities.java import jimport
  from ..constants.image import MD_SIZE_S, MD_SIZE_C, MD_SIZE_Z, MD_SIZE_T, MD_SIZE_Y, MD_SIZE_X, BIOFORMATS_IMAGE_EXTENSIONS
  from ..reader import Reader
label_desc: Use image node_id 4 for calling the BioformatsReader obj's underlying member method code with example usage: obj.read(series, index, c, z, t, rescale, xywh, wants_max_intensity, channel_names, XYWH) and returns: image, image,  scale