A faster convert that works directly with a specific raster
500625
static void bufferedToPlanar_F32(DataBufferByte buffer, WritableRaster src, Planar<GrayF32> dst) {
		byte[] srcData = buffer.getData();

		int numBands = src.getNumBands();

		int srcStride = stride(src);
		int srcOffset = getOffset(src);

		if(BoofConcurrency.USE_CONCURRENT ) {
			if (numBands == 3) {
				ImplConvertRaster_MT.from_3BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 1) {
				ImplConvertRaster_MT.from_1BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 4) {
				ImplConvertRaster_MT.from_4BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else {
				throw new RuntimeException("Write more code here.");
			}
		} else {
			if (numBands == 3) {
				ImplConvertRaster.from_3BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 1) {
				ImplConvertRaster.from_1BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 4) {
				ImplConvertRaster.from_4BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else {
				throw new RuntimeException("Write more code here.");
			}
		}
	}
37739
def ior_effect(durations, angle_diffs, length_diffs,
               summary_stat=np.mean, parallel=True, min_samples=20):
    
    raster = np.empty((len(e_dist) - 1, len(e_angle) - 1), dtype=object)
    for a, (a_low, a_upp) in enumerate(zip(e_angle[:-1], e_angle[1:])):
        for d, (d_low, d_upp) in enumerate(zip(e_dist[:-1], e_dist[1:])):
            idx = ((d_low <= length_diffs) & (length_diffs < d_upp) &
                   (a_low <= angle_diffs) & (angle_diffs < a_upp))
            if sum(idx) < min_samples:
                raster[d, a] = np.array([np.nan])
            else:
                raster[d, a] = durations[idx]
    if parallel:
        p = pool.Pool(3)
        result = p.map(summary_stat, list(raster.flatten()))
        p.terminate()
    else:
        result = list(map(summary_stat, list(raster.flatten())))
    for idx, value in enumerate(result):
        i, j = np.unravel_index(idx, raster.shape)
        raster[i, j] = value
    return raster
950550
public void setPixelValue(WritableRaster raster, int x, int y,
			int unsignedPixelValue) {
		short pixelValue = getPixelValue(unsignedPixelValue);
		setPixelValue(raster, x, y, pixelValue);
	}
43482
def _rts_from_ra(ra, tspan, labels, block=True):
    """"""
    def _convert(a, tspan, labels):
        from nsim import Timeseries
        return Timeseries(a, tspan, labels)
    return distob.call(
            _convert, ra, tspan, labels, prefer_local=False, block=block)
165763
def _coarsenImage(image, f):
    '''
    
    '''
    from skimage.morphology import square
    from skimage.filters import rank
    from skimage.transform._warps import rescale
    selem = square(f)
    arri = rank.mean(image, selem=selem)
    return rescale(arri, 1 / f, order=0)
1032203
def aggregate(self, block_size):
        '''
        
        '''
        raster2 = block_reduce(self.raster, block_size, func=np.ma.sum)
        geot = self.geot
        geot = (geot[0], block_size[0] * geot[1], geot[2], geot[3], geot[4],
                block_size[1] * geot[-1])
        return GeoRaster(raster2, geot, nodata_value=self.nodata_value,\
                        projection=self.projection, datatype=self.datatype)
1338436
private byte[] convert(Bitmap bitmap, String format) {
        final int width = bitmap.getWidth();
        final int height = bitmap.getHeight();

        DataBuffer buffer = new DataBufferByte(bitmap.getPixels(), bitmap.getLength());
        WritableRaster writableRaster = Raster.createPackedRaster(buffer, width, height, width, MASKS, null);
        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        bufferedImage.setData(writableRaster);

        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            ImageIO.write(bufferedImage, format, outputStream);
            outputStream.close();
            return outputStream.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
1197015
def _transform_fast(self, result, obj, func_nm):
        
        # if there were groups with no observations (Categorical only?)
        # try casting data to original dtype
        cast = self._transform_should_cast(func_nm)

        # for each col, reshape to to size of original frame
        # by take operation
        ids, _, ngroup = self.grouper.group_info
        output = []
        for i, _ in enumerate(result.columns):
            res = algorithms.take_1d(result.iloc[:, i].values, ids)
            if cast:
                res = self._try_cast(res, obj.iloc[:, i])
            output.append(res)

        return DataFrame._from_arrays(output, columns=result.columns,
                                      index=obj.index)
321420
def _diff_image(slice1, slice2,
                abs_value=True,
                cmap='gray',
                **kwargs):
    """"""

    diff = slice1 - slice2

    if abs_value:
        diff = np.abs(diff)

    return diff, cmap
1111240
public int getUnsignedPixelValue(WritableRaster raster, int x, int y) {
		short pixelValue = getPixelValue(raster, x, y);
		int unsignedPixelValue = getUnsignedPixelValue(pixelValue);
		return unsignedPixelValue;
	}
59311
private void getMapRow( int currentrow, ByteBuffer rowdata, boolean iscompressed ) throws IOException, DataFormatException {
        // if (logger.isDebugEnabled())
        // {
        // logger.debug("ACCESSING THE FILE at row: " + currentrow +
        // ", rasterMapType = " + rasterMapType +
        // ", numberOfBytesPerValue = " + numberOfBytesPerValue +
        // ", iscompressed = " + iscompressed);
        // }

        if (iscompressed) {
            /* Compressed maps */
            if (rasterMapType == -2) {
                /* Compressed double map */
                readCompressedFPRowByNumber(rowdata, currentrow, addressesofrows, cellFile, numberOfBytesPerValue);
            } else if (rasterMapType == -1) {
                /* Compressed floating point map */
                readCompressedFPRowByNumber(rowdata, currentrow, addressesofrows, cellFile, numberOfBytesPerValue);
            } else if (rasterMapType > 0) {
                /* Compressed integer map */
                readCompressedIntegerRowByNumber(rowdata, currentrow, addressesofrows, cellFile);
            } else {
                // if (logger.isDebugEnabled())
                // logger.error("format not double nor float");
            }
        } else {
            if (rasterMapType < 0) {
                /* Uncompressed floating point map */
                readUncompressedFPRowByNumber(rowdata, currentrow, cellFile, numberOfBytesPerValue);
            } else if (rasterMapType > 0) {
                /* Uncompressed integer map */
                readUncompressedIntegerRowByNumber(rowdata, currentrow, cellFile);
            } else {
                // if (logger.isDebugEnabled())
                // logger.error("Unknown case, iscompressed=" + iscompressed
                // + ", compressed=" + compressed + ", rasterMapType="
                // + rasterMapType);
            }
        }
        return;
    }
159366
def _pixel_to_tile(x: float, y: float) -> Tuple[float, float]:
    """"""
    xy = tcod.ffi.new("double[2]", (x, y))
    tcod.lib.TCOD_sys_pixel_to_tile(xy, xy + 1)
    return xy[0], xy[1]
1297668
def getCol(self, column, numberColumns=None):
        
        column = int(column)
        if self._raster[0] == 0 or self._raster[1] == 0:
            return self
        if numberColumns is None or numberColumns < 1 or numberColumns > 9:
            numberColumns = self._raster[1]
        columnWidth = self.w / numberColumns
        if column < 0:
            # If column is negative, count backwards from the end
            column = numberColumns - column
            if column < 0:
                # Bad column index, return last column
                return Region(self.x+self.w-columnWidth, self.y, columnWidth, self.h)
        elif column > numberColumns:
            # Bad column index, return first column
            return Region(self.x, self.y, columnWidth, self.h)
        return Region(self.x + (column * columnWidth), self.y, columnWidth, self.h)
1064129
function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
    // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
    // not the usual [0, 1]. If a command like setFillColor is used the src
    // values will already be within the correct range. However, if we are
    // converting an image we have to map the values to the correct range given
    // above.
    // Ls,as,bs <---> L*,a*,b* in the spec
    var Ls = src[srcOffset];
    var as = src[srcOffset + 1];
    var bs = src[srcOffset + 2];
    if (maxVal !== false) {
      Ls = decode(Ls, maxVal, 0, 100);
      as = decode(as, maxVal, cs.amin, cs.amax);
      bs = decode(bs, maxVal, cs.bmin, cs.bmax);
    }

    // Adjust limits of 'as' and 'bs'
    as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
    bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;

    // Computes intermediate variables X,Y,Z as per spec
    var M = (Ls + 16) / 116;
    var L = M + (as / 500);
    var N = M - (bs / 200);

    var X = cs.XW * fn_g(L);
    var Y = cs.YW * fn_g(M);
    var Z = cs.ZW * fn_g(N);

    var r, g, b;
    // Using different conversions for D50 and D65 white points,
    // per http://www.color.org/srgb.pdf
    if (cs.ZW < 1) {
      // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
      r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
      g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
      b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
    } else {
      // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
      r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
      g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
      b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
    }
    // clamp color values to [0,1] range then convert to [0,255] range.
    dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
    dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
    dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  }
480982
def raster_to_shape(raster):
    """"""
    left = raster.bounds.left
    right = raster.bounds.right
    top = raster.bounds.top
    bottom = raster.bounds.bottom

    top_left = (left, top)
    top_right = (right, top)
    bottom_left = (left, bottom)
    bottom_right = (right, bottom)

    return Polygon((
        top_left, top_right, bottom_right, bottom_left, top_left,
    ))
597703
def pilscale(self, r):
        
        return r * float(self.upsamplefactor) / float(self.binfactor)
1188768
function deinterlace(pixels, width) {

                    var newPixels = new Array(pixels.length);
                    var rows = pixels.length / width;
                    var cpRow = function(toRow, fromRow) {
                        var fromPixels = pixels.slice(fromRow * width, (fromRow + 1) * width);
                        newPixels.splice.apply(newPixels, [toRow * width, width].concat(fromPixels));
                    };

                    // See appendix E.
                    var offsets = [0, 4, 2, 1];
                    var steps = [8, 8, 4, 2];

                    var fromRow = 0;
                    for (var pass = 0; pass < 4; pass++) {
                        for (var toRow = offsets[pass]; toRow < rows; toRow += steps[pass]) {
                            cpRow(toRow, fromRow);
                            fromRow++;
                        }
                    }

                    return newPixels;
                }