func SubsetAndRescaleImage(baseImg image.Image, topLeftX, topLeftY, bottomRightX, bottomRightY, scale, dilation int) (image.Image, error) {

	// Correct max bounds if left unset (i.e., 0)
	imgBounds := baseImg.Bounds()
	if bottomRightX == 0 {
		bottomRightX = imgBounds.Max.X
	}
	if bottomRightY == 0 {
		bottomRightY = imgBounds.Max.Y
	}

	// Dilate, if necessary
	topLeftX = DilateDimension(topLeftX, imgBounds.Max.X, dilation, WhichPointTopLeft)
	topLeftY = DilateDimension(topLeftY, imgBounds.Max.Y, dilation, WhichPointTopLeft)
	bottomRightX = DilateDimension(bottomRightX, imgBounds.Max.X, dilation, WhichPointBottomRight)
	bottomRightY = DilateDimension(bottomRightY, imgBounds.Max.Y, dilation, WhichPointBottomRight)

	subImg, ok := baseImg.(*image.RGBA)
	if !ok {
		// Previously we failed if the image wasn't natively image.RGBA. Now we
		// will draw the image into in image.RGBA.
		b := baseImg.Bounds()
		subImg = image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
		draw.Draw(subImg, subImg.Bounds(), baseImg, b.Min, draw.Src)
	}

	// First extract the bounded region of interest
	cutImg := subImg.SubImage(image.Rect(topLeftX, topLeftY, bottomRightX, bottomRightY))

	// Now apply the scale
	width := (bottomRightX - topLeftX) * scale
	outImg := imaging.Resize(cutImg, width, 0, imaging.NearestNeighbor)

	return outImg, nil
}
// SubsetAndRescaleImage takes an input image, crops based on a top left point
// and a bottom right point, dilates, and then rescales the image.
SubsetAndRescaleImage takes an input image, crops based on a top left point
and a bottom right point, dilates, and then rescales the image.
// SubsetAndRescaleImage takes an input image crops based on a top left point // and a bottom right point dilates and then rescales the image .
func SubsetAndRescaleImage(baseImg image.Image, topLeftX, topLeftY, bottomRightX, bottomRightY, scale, dilation int) (image.Image, error) {
	imgBounds := baseImg.Bounds()
	if bottomRightX == 0 {
		bottomRightX = imgBounds.Max.X
	}
	if bottomRightY == 0 {
		bottomRightY = imgBounds.Max.Y
	}
	topLeftX = DilateDimension(topLeftX, imgBounds.Max.X, dilation, WhichPointTopLeft)
	topLeftY = DilateDimension(topLeftY, imgBounds.Max.Y, dilation, WhichPointTopLeft)
	bottomRightX = DilateDimension(bottomRightX, imgBounds.Max.X, dilation, WhichPointBottomRight)
	bottomRightY = DilateDimension(bottomRightY, imgBounds.Max.Y, dilation, WhichPointBottomRight)
	subImg, ok := baseImg.(*image.RGBA)
	if !ok {
		b := baseImg.Bounds()
		subImg = image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
		draw.Draw(subImg, subImg.Bounds(), baseImg, b.Min, draw.Src)
	}
	cutImg := subImg.SubImage(image.Rect(topLeftX, topLeftY, bottomRightX, bottomRightY))
	width := (bottomRightX - topLeftX) * scale
	outImg := imaging.Resize(cutImg, width, 0, imaging.NearestNeighbor)
	return outImg, nil
}
func SubsetAndRescaleImage ( baseImg image . Image , topLeftX , topLeftY , bottomRightX , bottomRightY , scale , dilation int ) ( image . Image , error ) { imgBounds := baseImg . Bounds ( ) if bottomRightX == 0 { bottomRightX = imgBounds . Max . X } if bottomRightY == 0 { bottomRightY = imgBounds . Max . Y } topLeftX = DilateDimension ( topLeftX , imgBounds . Max . X , dilation , WhichPointTopLeft ) topLeftY = DilateDimension ( topLeftY , imgBounds . Max . Y , dilation , WhichPointTopLeft ) bottomRightX = DilateDimension ( bottomRightX , imgBounds . Max . X , dilation , WhichPointBottomRight ) bottomRightY = DilateDimension ( bottomRightY , imgBounds . Max . Y , dilation , WhichPointBottomRight ) subImg , ok := baseImg . ( * image . RGBA ) if ! ok { b := baseImg . Bounds ( ) subImg = image . NewRGBA ( image . Rect ( 0 , 0 , b . Dx ( ) , b . Dy ( ) ) ) draw . Draw ( subImg , subImg . Bounds ( ) , baseImg , b . Min , draw . Src ) } cutImg := subImg . SubImage ( image . Rect ( topLeftX , topLeftY , bottomRightX , bottomRightY ) ) width := ( bottomRightX - topLeftX ) * scale outImg := imaging . Resize ( cutImg , width , 0 , imaging . NearestNeighbor ) return outImg , nil }
SubsetAndRescaleImage takes an input image, crops based on a top left point
and a bottom right point, dilates, and then rescales the image.
SubsetAndRescaleImage takes an input image crops based on a top left point and a bottom right point dilates and then rescales the image .
// Correct max bounds if left unset (i.e., 0) // Dilate, if necessary // Previously we failed if the image wasn't natively image.RGBA. Now we // will draw the image into in image.RGBA. // First extract the bounded region of interest // Now apply the scale