remove lens distortion from given image
495529
def correct(self, image, keepSize=False, borderValue=0):
        '''
        
        '''
        image = imread(image)
        (h, w) = image.shape[:2]
        mapx, mapy = self.getUndistortRectifyMap(w, h)
        self.img = cv2.remap(image, mapx, mapy, cv2.INTER_LINEAR,
                             borderMode=cv2.BORDER_CONSTANT,
                             borderValue=borderValue
                             )
        if not keepSize:
            xx, yy, ww, hh = self.roi
            self.img = self.img[yy: yy + hh, xx: xx + ww]
        return self.img
1317877
function (image, old) {
        var data1 = old.data,
            data2 = image.data,
            w1 = old.width,
            w2 = image.width,
            px1 = old.globalOffset.x,
            py1 = old.globalOffset.y,
            px2 = image.globalOffset.x,
            py2 = image.globalOffset.y,
            b1 = old.bounds,
            b2 = image.bounds,
            px = Math.min(b1.minX + px1, b2.minX + px2), // global offset for new image (by min in bounds)
            py = Math.min(b1.minY + py1, b2.minY + py2),
            b = { // bounds for new image include all of the pixels [0,0,width,height] (reduce to bounds)
                minX: 0,
                minY: 0,
                maxX: Math.max(b1.maxX + px1, b2.maxX + px2) - px,
                maxY: Math.max(b1.maxY + py1, b2.maxY + py2) - py,
            },
            w = b.maxX + 1, // size for new image
            h = b.maxY + 1,
            i, j, k, k1, k2, len;

        var result = new Uint8Array(w * h);

        // copy all old image
        len = b1.maxX - b1.minX + 1;
        i = (py1 - py + b1.minY) * w + (px1 - px + b1.minX);
        k1 = b1.minY * w1 + b1.minX;
        k2 = b1.maxY * w1 + b1.minX + 1;
        // walk through rows (Y)
        for (k = k1; k < k2; k += w1) {
            result.set(data1.subarray(k, k + len), i); // copy row
            i += w;
        }

        // copy new image (only "black" pixels)
        len = b2.maxX - b2.minX + 1;
        i = (py2 - py + b2.minY) * w + (px2 - px + b2.minX);
        k1 = b2.minY * w2 + b2.minX;
        k2 = b2.maxY * w2 + b2.minX + 1;
        // walk through rows (Y)
        for (k = k1; k < k2; k += w2) {
            // walk through cols (X)
            for (j = 0; j < len; j++) {
                if (data2[k + j] === 1) result[i + j] = 1;
            }
            i += w;
        }

        return {
            data: result,
            width: w,
            height: h,
            bounds: b,
            globalOffset: {
                x: px,
                y: py,
            }
        };
    }
1277838
def clean(image, mask=None, iterations = 1):
    '''
    '''
    global clean_table
    if mask is None:
        masked_image = image
    else:
        masked_image = image.astype(bool).copy()
        masked_image[~mask] = False
    result = table_lookup(masked_image, clean_table, False, iterations)
    if not mask is None:
        result[~mask] = image[~mask]
    return result
1013178
def match_via_squared_difference(image, template, raw_tolerance=1, sq_diff_tolerance=0.1):
    
    h, w = image.shape
    th, tw = template.shape
    # fft based convolution enables fast matching of large images
    correlation = fftconvolve(image, template[::-1,::-1])
    # trim the returned image, fftconvolve returns an image of width: (Temp_w-1) + Im_w + (Temp_w -1), likewise height
    correlation = correlation[th-1:h, tw-1:w]
    # find images regions which are potentially matches
    match_position_dict = get_tiles_at_potential_match_regions(image, template, correlation, raw_tolerance=raw_tolerance)
    # bright spots in images can lead to false positivies- the normalisation carried out here eliminates those
    results = calculate_squared_differences(match_position_dict, correlation, template, sq_diff_tolerance=sq_diff_tolerance)
    return results
1161082
private void removeDistortionFromContour(List<Point2D_I32> distorted , FastQueue<Point2D_I32> undistorted  ) {
		undistorted.reset();

		for (int j = 0; j < distorted.size(); j++) {
			// remove distortion
			Point2D_I32 p = distorted.get(j);
			Point2D_I32 q = undistorted.grow();

			distToUndist.compute(p.x,p.y,distortedPoint);

			// round to minimize error
			q.x = Math.round(distortedPoint.x);
			q.y = Math.round(distortedPoint.y);
		}
	}
1128154
def fitImg(self, img_rgb):
        '''
        
        '''
        H = self.pattern.findHomography(img_rgb)[0]
        H_inv = self.pattern.invertHomography(H)
        s = self.img_orig.shape
        warped = cv2.warpPerspective(img_rgb, H_inv, (s[1], s[0]))
        return warped
985752
def clip(self, px, py, w, h, img):
        ''''''
        sx = 0
        sy = 0

        if px < 0:
            sx = -px
            w += px
            px = 0
        if py < 0:
            sy = -py
            h += py
            py = 0
        if px+w > img.width:
            w = img.width - px
        if py+h > img.height:
            h = img.height - py
        return (px, py, sx, sy, w, h)
527768
def remove(image):
    """"""
    path = os.path.join(IMG_DIR, image)
    if os.path.isfile(path):
        os.remove(path)
139934
public static GrayU8 createMask( CameraUniversalOmni model ,
									 LensDistortionWideFOV distortion , double fov ) {
		GrayU8 mask = new GrayU8(model.width,model.height);

		Point2Transform3_F64 p2s = distortion.undistortPtoS_F64();
		Point3D_F64 ref = new Point3D_F64(0,0,1);
		Point3D_F64 X = new Point3D_F64();

		p2s.compute(model.cx,model.cy,X);

		for (int y = 0; y < model.height; y++) {
			for (int x = 0; x < model.width; x++) {
				p2s.compute(x,y,X);

				if( Double.isNaN(X.x) || Double.isNaN(X.y) || Double.isNaN(X.z)) {
					continue;
				}

				double angle = UtilVector3D_F64.acute(ref,X);
				if( Double.isNaN(angle)) {
					continue;
				}
				if( angle <= fov/2.0 )
					mask.unsafe_set(x,y,1);
			}
		}
		return mask;
	}
795945
def _extract_mask_distance(image, mask = slice(None), voxelspacing = None):
    
    if isinstance(mask, slice):
        mask = numpy.ones(image.shape, numpy.bool)
    
    distance_map = distance_transform_edt(mask, sampling=voxelspacing)
    
    return _extract_intensities(distance_map, mask)
309807
def _remove_edge(im, r):
    
    '''
    edge = sp.ones_like(im)
    if len(im.shape) == 2:
        sx, sy = im.shape
        edge[r:sx-r, r:sy-r] = im[r:sx-r, r:sy-r]
    else:
        sx, sy, sz = im.shape
        edge[r:sx-r, r:sy-r, r:sz-r] = im[r:sx-r, r:sy-r, r:sz-r]
    return edge
269526
def image_shift(xshift=0, yshift=0, axes="gca"):
    

    if axes=="gca": axes = _pylab.gca()

    e = axes.images[0].get_extent()

    e[0] = e[0] + xshift
    e[1] = e[1] + xshift
    e[2] = e[2] + yshift
    e[3] = e[3] + yshift

    axes.images[0].set_extent(e)

    _pylab.draw()
824792
def unflatten_dct(obj):
    

    def reduce_func(accum, key_string_and_value):
        key_string = key_string_and_value[0]
        value = key_string_and_value[1]
        item_key_path = key_string_to_lens_path(key_string)
        # All but the last segment gives us the item container len
        container_key_path = init(item_key_path)
        container = unless(
            # If the path has any length (not []) and the value is set, don't do anything
            both(always(length(container_key_path)), fake_lens_path_view(container_key_path)),
            # Else we are at the top level, so use the existing accum or create a [] or {}
            # depending on if our item key is a number or not
            lambda x: default_to(
                if_else(
                    lambda segment: segment.isnumeric(),
                    always([]),
                    always({})
                )(head(item_key_path))
            )(x)
        )(accum)
        # Finally set the container at the itemLensPath
        return fake_lens_path_set(
            item_key_path,
            value,
            container
        )

    return compose(
        reduce(
            reduce_func,
            # null initial value
            None
        ),
        to_pairs
    )(obj)
962750
def fom(reco, true_image):
    """"""
    gradient = odl.Gradient(reco.space)
    return (gradient(reco - true_image).norm() +
            reco.space.dist(reco, true_image))
349748
def gauss_blur( sigma, max_error = 1.0 / 0x100 )
      filter_type = DFLOAT.align typecode
      filter = Sequence[ *Array.gauss_blur_filter( sigma, max_error / dimension ) ].
        to_type filter_type
      ( dimension - 1 ).downto( 0 ).inject self do |retval,i|
        retval.convolve filter
      end
    end
100137
def _clear(self):
        
        self._plain_image = [" " * self._width for _ in range(self._height)]
        self._colour_map = [[(None, 0, 0) for _ in range(self._width)]
                            for _ in range(self._height)]
428702
def standardize_images(x):
  """"""
  with tf.name_scope("standardize_images", values=[x]):
    x_shape = shape_list(x)
    x = to_float(tf.reshape(x, [-1] + x_shape[-3:]))
    x_mean = tf.reduce_mean(x, axis=[1, 2], keepdims=True)
    x_variance = tf.reduce_mean(
        tf.squared_difference(x, x_mean), axis=[1, 2], keepdims=True)
    num_pixels = to_float(x_shape[-2] * x_shape[-3])
    x = (x - x_mean) / tf.maximum(tf.sqrt(x_variance), tf.rsqrt(num_pixels))
    return tf.reshape(x, x_shape)