SOR iteration for border pixels
160264
private float iterationSorSafe(GrayF32 image1, int x, int y, int pixelIndex) {
		float w = SOR_RELAXATION;

		float uf;
		float vf;
		float ui = initFlowX.data[pixelIndex];
		float vi = initFlowY.data[pixelIndex];

		float u = flowX.data[pixelIndex];
		float v = flowY.data[pixelIndex];

		float I1 = image1.data[pixelIndex];
		float I2 = warpImage2.data[pixelIndex];

		float I2x = warpDeriv2X.data[pixelIndex];
		float I2y = warpDeriv2Y.data[pixelIndex];

		float AU = A_safe(x,y,flowX);
		float AV = A_safe(x,y,flowY);

		flowX.data[pixelIndex] = uf = (1-w)*u + w*((I1-I2+I2x*ui - I2y*(v-vi))*I2x + alpha2*AU)/(I2x*I2x + alpha2);
		flowY.data[pixelIndex] = vf = (1-w)*v + w*((I1-I2+I2y*vi - I2x*(uf-ui))*I2y + alpha2*AV)/(I2y*I2y + alpha2);

		return (uf - u)*(uf - u) + (vf - v)*(vf - v);
	}
1219553
public static void convolveHV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) {
		int index = 0;
		float[] matrix = kernel.getKernelData( null );
		int rows = kernel.getHeight();
		int cols = kernel.getWidth();
		int rows2 = rows/2;
		int cols2 = cols/2;

		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				float r = 0, g = 0, b = 0, a = 0;

				for (int row = -rows2; row <= rows2; row++) {
					int iy = y+row;
					int ioffset;
					if (0 <= iy && iy < height)
						ioffset = iy*width;
					else if ( edgeAction == CLAMP_EDGES )
						ioffset = y*width;
					else if ( edgeAction == WRAP_EDGES )
						ioffset = ((iy+height) % height) * width;
					else
						continue;
					int moffset = cols*(row+rows2)+cols2;
					for (int col = -cols2; col <= cols2; col++) {
						float f = matrix[moffset+col];

						if (f != 0) {
							int ix = x+col;
							if (!(0 <= ix && ix < width)) {
								if ( edgeAction == CLAMP_EDGES )
									ix = x;
								else if ( edgeAction == WRAP_EDGES )
									ix = (x+width) % width;
								else
									continue;
							}
							int rgb = inPixels[ioffset+ix];
							a += f * ((rgb >> 24) & 0xff);
							r += f * ((rgb >> 16) & 0xff);
							g += f * ((rgb >> 8) & 0xff);
							b += f * (rgb & 0xff);
						}
					}
				}
				int ia = alpha ? PixelUtils.clamp((int)(a+0.5)) : 0xff;
				int ir = PixelUtils.clamp((int)(r+0.5));
				int ig = PixelUtils.clamp((int)(g+0.5));
				int ib = PixelUtils.clamp((int)(b+0.5));
				outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
			}
		}
	}
200500
public static void composeThroughMask(Raster src, WritableRaster dst, Raster sel) {
		int x = src.getMinX();
		int y = src.getMinY();
		int w = src.getWidth();
		int h = src.getHeight();

		int srcRGB[] = null;
		int selRGB[] = null;
		int dstRGB[] = null;

		for ( int i = 0; i < h; i++ ) {
			srcRGB = src.getPixels(x, y, w, 1, srcRGB);
			selRGB = sel.getPixels(x, y, w, 1, selRGB);
			dstRGB = dst.getPixels(x, y, w, 1, dstRGB);

			int k = x;
			for ( int j = 0; j < w; j++ ) {
				int sr = srcRGB[k];
				int dir = dstRGB[k];
				int sg = srcRGB[k+1];
				int dig = dstRGB[k+1];
				int sb = srcRGB[k+2];
				int dib = dstRGB[k+2];
				int sa = srcRGB[k+3];
				int dia = dstRGB[k+3];

				float a = selRGB[k+3]/255f;
				float ac = 1-a;

				dstRGB[k] = (int)(a*sr + ac*dir); 
				dstRGB[k+1] = (int)(a*sg + ac*dig); 
				dstRGB[k+2] = (int)(a*sb + ac*dib); 
				dstRGB[k+3] = (int)(a*sa + ac*dia);
				k += 4;
			}

			dst.setPixels(x, y, w, 1, dstRGB);
			y++;
		}
	}
1042886
private static void thresholdBlock(byte[] luminances,
                                     int xoffset,
                                     int yoffset,
                                     int threshold,
                                     int stride,
                                     BitMatrix matrix) {
    for (int y = 0, offset = yoffset * stride + xoffset; y < BLOCK_SIZE; y++, offset += stride) {
      for (int x = 0; x < BLOCK_SIZE; x++) {
        // Comparison needs to be <= so that black == 0 pixels are black even if the threshold is 0.
        if ((luminances[offset + x] & 0xFF) <= threshold) {
          matrix.set(xoffset + x, yoffset + y);
        }
      }
    }
  }
378264
private float iterationSor(GrayF32 image1, GrayF32 deriv1X, GrayF32 deriv1Y,
							   int i, int ipx, int imx, int ipy, int imy) {
		float w = SOR_RELAXATION;

		// these variables could be precomputed once.  See equation 11
		float psid = psiData.data[i];
		float psig = gamma*psiGradient.data[i];

		float di = warpImage2.data[i] - image1.data[i];
		float dx2 = warpDeriv2X.data[i];
		float dy2 = warpDeriv2Y.data[i];
		float dxx2 = warpDeriv2XX.data[i];
		float dyy2 = warpDeriv2YY.data[i];
		float dxy2 = warpDeriv2XY.data[i];

		float Au = -psid*di*dx2 + alpha*divU.data[i]
				- psig*((dx2 - deriv1X.data[i])*warpDeriv2XX.data[i] + (dy2 - deriv1Y.data[i])*warpDeriv2XY.data[i]);

		float Av = -psid*di*dy2 + alpha*divV.data[i]
				- psig*((dx2 - deriv1X.data[i])*warpDeriv2XY.data[i] + (dy2 - deriv1Y.data[i])*warpDeriv2YY.data[i]);

		float Du = psid*dx2*dx2 + psig*(dxx2*dxx2 + dxy2*dxy2) + alpha*divD.data[i];
		float Dv = psid*dy2*dy2 + psig*(dyy2*dyy2 + dxy2*dxy2) + alpha*divD.data[i];
		float D = psid*dx2*dy2 + psig*(dxx2 + dyy2)*dxy2;

		// update the change in flow
		float psi_index = psiSmooth.data[i];
		float coef0 = 0.5f*(psiSmooth.data[ipx] + psi_index);
		float coef1 = 0.5f*(psiSmooth.data[imx] + psi_index);
		float coef2 = 0.5f*(psiSmooth.data[ipy] + psi_index);
		float coef3 = 0.5f*(psiSmooth.data[imy] + psi_index);

		float div_du = coef0 * du.data[ipx] + coef1 * du.data[imx] + coef2 * du.data[ipy] + coef3 * du.data[imy];
		float div_dv = coef0 * dv.data[ipx] + coef1 * dv.data[imx] + coef2 * dv.data[ipy] + coef3 * dv.data[imy] ;

		final float dui = du.data[i];
		final float dvi = dv.data[i];

		du.data[i] = (1f-w)*dui + w*(Au - D*dvi + alpha*div_du)/Du;
		dv.data[i] = (1f-w)*dvi + w*(Av - D*du.data[i] + alpha*div_dv)/Dv;

		return (du.data[i] - dui) * (du.data[i] - dui) + (dv.data[i] - dvi) * (dv.data[i] - dvi);
	}
244679
def finite_pixels(self):
        
        finite_px = np.where(np.isfinite(self.data))
        finite_px = np.c_[finite_px[0], finite_px[1]]
        return finite_px
907566
def colRowIsOnSciencePixelList(self, col, row, padding=DEFAULT_PADDING):
        """"""
        out = np.ones(len(col), dtype=bool)
        col_arr = np.array(col)
        row_arr = np.array(row)
        mask = np.bitwise_or(col_arr < 12. - padding, col_arr > 1111 + padding)
        out[mask] = False
        mask = np.bitwise_or(row_arr < 20. - padding, row_arr > 1043 + padding)
        out[mask] = False
        return out
1110719
def erode_edge(dem, iterations=1):
    
    import scipy.ndimage as ndimage 
    print('Eroding pixels near nodata: %i iterations' % iterations)
    mask = np.ma.getmaskarray(dem)
    mask_dilate = ndimage.morphology.binary_dilation(mask, iterations=iterations)
    out = np.ma.array(dem, mask=mask_dilate)
    return out
802373
void applyToBorder(GrayU8 input, GrayU8 output, int y0, int y1, int x0, int x1, ApplyHelper h) {
		// top-left corner
		h.computeHistogram(0,0,input);
		h.applyToBlock(0,0,x0+1,y0+1,input,output);
		// top-middle
		for (int x = x0+1; x < x1; x++) {
			h.updateHistogramX(x-x0,0,input);
			h.applyToBlock(x,0,x+1,y0,input,output);
		}
		// top-right
		h.updateHistogramX(x1-x0,0,input);
		h.applyToBlock(x1,0,input.width,y0+1,input,output);

		// middle-right
		for (int y = y0+1; y < y1; y++) {
			h.updateHistogramY(x1-x0,y-y0,input);
			h.applyToBlock(x1,y,input.width,y+1,input,output);
		}

		// bottom-right
		h.updateHistogramY(x1-x0,y1-y0,input);
		h.applyToBlock(x1,y1,input.width,input.height,input,output);

		//Start over in the top-left. Yes this step could be avoided...

		// middle-left
		h.computeHistogram(0,0,input);

		for (int y = y0+1; y < y1; y++) {
			h.updateHistogramY(0,y-y0,input);
			h.applyToBlock(0,y,x0,y+1,input,output);
		}

		// bottom-left
		h.updateHistogramY(0,y1-y0,input);
		h.applyToBlock(0,y1,x0+1,input.height,input,output);

		// bottom-middle
		for (int x = x0+1; x < x1; x++) {
			h.updateHistogramX(x-x0,y1-y0,input);
			h.applyToBlock(x,y1,x+1,input.height,input,output);
		}
	}
437090
def map_pixels_to_ascii_chars(image, range_width=25):
    

    pixels_in_image = list(image.getdata())
    pixels_to_chars = [ASCII_CHARS[pixel_value/range_width] for pixel_value in
            pixels_in_image]

    return "".join(pixels_to_chars)
740592
function(mask) {
        var borders = ['border-top','border-right', 'border-bottom', 'border-left'];
        var res = {};
        for (var i = 0; i < 4; i++) {
            if (!(mask & bin(i))) res[borders[i]] = 'none';
        }
        return res;
    }
812633
def array_scanlines_interlace(self, pixels):
        

        # http://www.w3.org/TR/PNG/#8InterlaceMethods
        # Array type.
        fmt = 'BH'[self.bitdepth > 8]
        # Value per row
        vpr = self.width * self.planes

        # Each iteration generates a scanline starting at (x, y)
        # and consisting of every xstep pixels.
        for lines in adam7_generate(self.width, self.height):
            for x, y, xstep in lines:
                # Pixels per row (of reduced image)
                ppr = int(math.ceil((self.width - x) / float(xstep)))
                # Values per row (of reduced image)
                reduced_row_len = ppr * self.planes
                if xstep == 1:
                    # Easy case: line is a simple slice.
                    offset = y * vpr
                    yield pixels[offset: offset + vpr]
                    continue
                # We have to step by xstep,
                # which we can do one plane at a time
                # using the step in Python slices.
                row = array(fmt)
                # There's no easier way to set the length of an array
                row.extend(pixels[0:reduced_row_len])
                offset = y * vpr + x * self.planes
                end_offset = (y + 1) * vpr
                skip = self.planes * xstep
                for i in range(self.planes):
                    row[i::self.planes] = \
                        pixels[offset + i: end_offset: skip]
                yield row
820383
private void createDetectedList(int which, List<PointIndex2D_F64> pixels) {
		detected2D3D.clear();
		List<Point2D3D> all = getControl3D(which);
		for (int i = 0; i < pixels.size(); i++) {
			PointIndex2D_F64 a = pixels.get(i);
			Point2D3D b = all.get(i);

			pixelToNorm.compute(a.x,a.y, b.observation);
			detected2D3D.add( b );
		}
	}
570785
def getPixmap(self, matrix=None, colorspace=None, alpha=0):
        """"""
        CheckParent(self)

        return _fitz.Annot_getPixmap(self, matrix, colorspace, alpha)
437516
private void process(int x,int y)
    {
        int A = getSourcePixel(x-1,y-1);
        int B = getSourcePixel(x,y-1);
        int C = getSourcePixel(x+1,y-1);
        int D = getSourcePixel(x-1,y);
        int E = getSourcePixel(x,y);
        int F = getSourcePixel(x+1,y);
        int G = getSourcePixel(x-1,y+1);
        int H = getSourcePixel(x,y+1);
        int I = getSourcePixel(x+1,y+1);
        int E0 = E;
        int E1 = E;
        int E2 = E;
        int E3 = E;
        
        if (different(B,H) && different(D,F)) {
            E0 = !different(D,B) ? D : E;
            E1 = !different(B,F) ? F : E;
            E2 = !different(D,H) ? D : E;
            E3 = !different(H,F) ? F : E;
        }
        
        setDestPixel(x*2,y*2,E0);
        setDestPixel((x*2)+1,y*2,E1);
        setDestPixel((x*2),(y*2)+1,E2);
        setDestPixel((x*2)+1,(y*2)+1,E3);
    }
799553
def pixel(self, x, y, size=None):
        """"""
        if (size is None):
            size = self.sz
        # Have we go to the smallest element?
        if (size <= 3):
            if (_not_diagonal(x, y)):
                return None
            else:
                return (0, 0, 0)
        divisor = size // 3
        if (_not_diagonal(x // divisor, y // divisor)):
            return None
        return self.pixel(x % divisor, y % divisor, divisor)
864794
public void process(GrayU8 binary , GrayS32 labeled ) {
		// initialize data structures
		labeled.reshape(binary.width,binary.height);

		// ensure that the image border pixels are filled with zero by enlarging the image
		if( border.width != binary.width+2 || border.height != binary.height+2)  {
			border.reshape(binary.width + 2, binary.height + 2);
			ImageMiscOps.fillBorder(border, 0, 1);
		}
		border.subimage(1,1,border.width-1,border.height-1, null).setTo(binary);

		// labeled image must initially be filled with zeros
		ImageMiscOps.fill(labeled,0);

		binary = border;
		packedPoints.reset();
		contours.reset();
		tracer.setInputs(binary,labeled, packedPoints);

		// Outside border is all zeros so it can be ignored
		int endY = binary.height-1, enxX = binary.width-1;
		for( y = 1; y < endY; y++ ) {
			indexIn = binary.startIndex + y*binary.stride+1;
			indexOut = labeled.startIndex + (y-1)*labeled.stride;

			x = 1;
			int delta = scanForOne(binary.data,indexIn,indexIn+enxX-x)-indexIn;
			x += delta;
			indexIn += delta;
			indexOut += delta;
			while( x < enxX ) {
				int label = labeled.data[indexOut];
				boolean handled = false;
				if( label == 0 && binary.data[indexIn - binary.stride ] != 1 ) {
					handleStep1();
					handled = true;
					label = contours.size;
				}
				// could be an external and internal contour
				if( binary.data[indexIn + binary.stride ] == 0 ) {
					handleStep2(labeled, label);
					handled = true;
				}
				if( !handled ) {
					// Step 3: Must not be part of the contour but an inner pixel and the pixel to the left must be
					// labeled
					if( labeled.data[indexOut] == 0 )
						labeled.data[indexOut] = labeled.data[indexOut-1];
				}

				delta = scanForOne(binary.data,indexIn+1,indexIn+enxX-x)-indexIn;
				x += delta;
				indexIn += delta;
				indexOut += delta;
			}
		}
	}