def write_image(self, arr, compression=None, write_rgb=False):
        compression = self._fix_compression (compression)

        arr = np.ascontiguousarray(arr)
        sample_format = None
        if arr.dtype in np.sctypes['float']:
            sample_format = SAMPLEFORMAT_IEEEFP
        elif arr.dtype in np.sctypes['uint']+[np.bool]:
            sample_format = SAMPLEFORMAT_UINT
        elif arr.dtype in np.sctypes['int']:
            sample_format = SAMPLEFORMAT_INT
        elif arr.dtype in np.sctypes['complex']:
            sample_format = SAMPLEFORMAT_COMPLEXIEEEFP
        else:
            raise NotImplementedError(`arr.dtype`)
        shape=arr.shape
        bits = arr.itemsize * 8

        if compression==COMPRESSION_NONE:
            WriteStrip = self.WriteRawStrip
        else:
            WriteStrip = self.WriteEncodedStrip

        self.SetField(TIFFTAG_COMPRESSION, compression)
        if (compression == COMPRESSION_LZW and
            sample_format in [SAMPLEFORMAT_INT, SAMPLEFORMAT_UINT]):
            # This field can only be set after compression and before writing data
            # Horizontal predictor often improves compression, but some rare
            # readers might support LZW only without predictor.
            self.SetField(TIFFTAG_PREDICTOR, PREDICTOR_HORIZONTAL)

        self.SetField(TIFFTAG_BITSPERSAMPLE, bits)
        self.SetField(TIFFTAG_SAMPLEFORMAT, sample_format)
        self.SetField(TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT)

        if len(shape)==1:
            shape = (shape[0], 1) # Same as 2D with height == 1

        if len(shape) == 2:
            height, width = shape
            size = width * height * arr.itemsize

            self.SetField(TIFFTAG_IMAGEWIDTH, width)
            self.SetField(TIFFTAG_IMAGELENGTH, height)
            self.SetField(TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK)
            self.SetField(TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)
            WriteStrip(0, arr.ctypes.data, size)            
            self.WriteDirectory()

        elif len(shape)==3:
            if write_rgb:
                # Guess the planar config, with a preference for separate planes
                if shape[2] == 3 or shape[2] == 4:
                    planar_config = PLANARCONFIG_CONTIG
                    height, width, depth = shape
                    size = arr.nbytes
                else:
                    planar_config = PLANARCONFIG_SEPARATE
                    depth, height, width = shape
                    size = width * height * arr.itemsize

                self.SetField(TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB)
                self.SetField(TIFFTAG_IMAGEWIDTH, width)
                self.SetField(TIFFTAG_IMAGELENGTH, height)
                self.SetField(TIFFTAG_SAMPLESPERPIXEL, depth)
                self.SetField(TIFFTAG_PLANARCONFIG, planar_config)
                if depth == 4: # RGBA
                    self.SetField(TIFFTAG_EXTRASAMPLES, [EXTRASAMPLE_UNASSALPHA],
                                  count=1)
                elif depth > 4: # No idea...
                    self.SetField(TIFFTAG_EXTRASAMPLES,
                                  [EXTRASAMPLE_UNSPECIFIED] * (depth - 3),
                                  count=(depth - 3))

                if planar_config == PLANARCONFIG_CONTIG:
                    WriteStrip(0, arr.ctypes.data, size)
                else:
                    for n in range(depth):
                        WriteStrip(n, arr[n, :, :].ctypes.data, size)
                self.WriteDirectory()
            else:
                depth, height, width = shape
                size = width * height * arr.itemsize
                for n in range(depth):
                    self.SetField(TIFFTAG_IMAGEWIDTH, width)
                    self.SetField(TIFFTAG_IMAGELENGTH, height)
                    self.SetField(TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK)
                    self.SetField(TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)

                    WriteStrip(0, arr[n].ctypes.data, size)
                    self.WriteDirectory()
        else:
            raise NotImplementedError (`shape`)
@ivar type: The name of the type,
dataset/ETHPy150Open pearu/pylibtiff/libtiff/libtiff_ctypes.py/TIFF.write_image--crossover with--dataset/ETHPy150Open ClusterHQ/eliot/eliot/_validation.py/MessageType.__init__