use of boofcv.abst.distort.FDistort in project BoofCV by lessthanoptimal.
the class CommonFitPolygonChecks method renderDistortedRectangles.
public void renderDistortedRectangles(boolean blackShape, Class imageType) {
orig = GeneralizedImageOps.createSingleBand(imageType, width, height);
image = GeneralizedImageOps.createSingleBand(imageType, width, height);
int white = blackShape ? this.white : this.black;
int black = blackShape ? this.black : this.white;
GImageMiscOps.fill(orig, white);
GImageMiscOps.fill(image, white);
distorted.clear();
for (Rectangle2D_I32 q : rectangles) {
if (fittingToBinaryImage)
GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0 + 1, q.y1 - q.y0 + 1);
else
GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0, q.y1 - q.y0);
Polygon2D_F64 tran = new Polygon2D_F64(4);
AffinePointOps_F64.transform(transform, q.x0, q.y0, tran.get(0));
AffinePointOps_F64.transform(transform, q.x0, q.y1, tran.get(1));
AffinePointOps_F64.transform(transform, q.x1, q.y1, tran.get(2));
AffinePointOps_F64.transform(transform, q.x1, q.y0, tran.get(3));
distorted.add(tran);
}
new FDistort(orig, image).border(white).affine(transform).apply();
if (showRendered) {
ListDisplayPanel panel = new ListDisplayPanel();
panel.addImage(orig, "Original");
panel.addImage(image, "Image");
ShowImages.showWindow(panel, "Rendered");
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
use of boofcv.abst.distort.FDistort in project BoofCV by lessthanoptimal.
the class CreateFiducialSquareImage method drawPattern.
@Override
protected void drawPattern(int patternID) throws IOException {
String imageName = new File(imagePaths.get(patternID)).getName();
GrayU8 image = UtilImageIO.loadImage(imagePaths.get(patternID), GrayU8.class);
if (image == null) {
System.err.println("Can't read image. Path = " + imagePaths.get(patternID));
System.exit(1);
// } else {
// System.out.println(" loaded "+imageName);
}
// make sure the image is square and divisible by 8
int s = image.width - (image.width % 8);
if (image.width != s || image.height != s) {
GrayU8 tmp = new GrayU8(s, s);
new FDistort(image, tmp).scaleExt().apply();
image = tmp;
}
GrayU8 binary = ThresholdImageOps.threshold(image, null, threshold, false);
if (showPreview)
ShowImages.showWindow(VisualizeBinaryData.renderBinary(binary, false, null), "Binary Image");
PixelMath.multiply(binary, 255, binary);
BufferedImage buffered = new BufferedImage(binary.width, binary.height, BufferedImage.TYPE_BYTE_GRAY);
ConvertBufferedImage.convertTo(binary, buffered, true);
PDImageXObject pdImage = JPEGFactory.createFromImage(document, buffered);
pcs.drawImage(pdImage, 0, 0, innerWidth, innerWidth);
}
use of boofcv.abst.distort.FDistort in project BoofCV by lessthanoptimal.
the class FactorySteerable method gaussian.
/**
* Steerable filter for 2D Gaussian derivatives. The basis is composed of a set of rotated kernels.
*
* @param kernelType Specifies which type of 2D kernel should be generated.
* @param orderX Order of the derivative in the x-axis.
* @param orderY Order of the derivative in the y-axis.
*
* @param sigma
*@param radius Radius of the kernel. @return Steerable kernel generator for the specified gaussian derivative.
*/
public static <K extends Kernel2D> SteerableKernel<K> gaussian(Class<K> kernelType, int orderX, int orderY, double sigma, int radius) {
if (orderX < 0 || orderX > 4)
throw new IllegalArgumentException("derivX must be from 0 to 4 inclusive.");
if (orderY < 0 || orderY > 4)
throw new IllegalArgumentException("derivT must be from 0 to 4 inclusive.");
int order = orderX + orderY;
if (order > 4) {
throw new IllegalArgumentException("The total order of x and y can't be greater than 4");
}
int maxOrder = Math.max(orderX, orderY);
if (sigma <= 0)
sigma = (float) FactoryKernelGaussian.sigmaForRadius(radius, maxOrder);
else if (radius <= 0)
radius = FactoryKernelGaussian.radiusForSigma(sigma, maxOrder);
Class kernel1DType = FactoryKernel.get1DType(kernelType);
Kernel1D kerX = FactoryKernelGaussian.derivativeK(kernel1DType, orderX, sigma, radius);
Kernel1D kerY = FactoryKernelGaussian.derivativeK(kernel1DType, orderY, sigma, radius);
Kernel2D kernel = GKernelMath.convolve(kerY, kerX);
Kernel2D[] basis = new Kernel2D[order + 1];
// convert it into an image which can be rotated
ImageGray image = GKernelMath.convertToImage(kernel);
ImageGray imageRotated = (ImageGray) image.createNew(image.width, image.height);
basis[0] = kernel;
// form the basis by created rotated versions of the kernel
double angleStep = Math.PI / basis.length;
for (int index = 1; index <= order; index++) {
float angle = (float) (angleStep * index);
GImageMiscOps.fill(imageRotated, 0);
new FDistort(image, imageRotated).rotate(angle).apply();
basis[index] = GKernelMath.convertToKernel(imageRotated);
}
SteerableKernel<K> ret;
if (kernelType == Kernel2D_F32.class)
ret = (SteerableKernel<K>) new SteerableKernel_F32();
else
ret = (SteerableKernel<K>) new SteerableKernel_I32();
ret.setBasis(FactorySteerCoefficients.polynomial(order), basis);
return ret;
}
use of boofcv.abst.distort.FDistort in project BoofCV by lessthanoptimal.
the class TestPyramidFloatGaussianScale method _update.
public void _update(GrayF32 img) {
InterpolatePixelS<GrayF32> interp = FactoryInterpolation.bilinearPixelS(img, BorderType.EXTENDED);
PyramidFloatGaussianScale<GrayF32> alg = new PyramidFloatGaussianScale<>(interp, scales, sigmas, imageType);
alg.process(img);
// test the first layer
BlurFilter<GrayF32> blur = FactoryBlurFilter.gaussian(ImageType.single(GrayF32.class), 3, -1);
GrayF32 blurrImg = new GrayF32(width, height);
blur.process(img, blurrImg);
GrayF32 expected = new GrayF32((int) Math.ceil(width / 3.0), (int) Math.ceil(height / 3.0));
new FDistort(blurrImg, expected).scaleExt().apply();
GrayF32 found = alg.getLayer(0);
BoofTesting.assertEquals(expected, found, 1e-4);
// test the second layer
blur = FactoryBlurFilter.gaussian(ImageType.single(GrayF32.class), sigmas[0], -1);
blurrImg = new GrayF32(expected.width, expected.height);
blur.process(expected, blurrImg);
expected = new GrayF32((int) Math.ceil(width / 5.0), (int) Math.ceil(height / 5.0));
new FDistort(blurrImg, expected).scaleExt().apply();
found = alg.getLayer(1);
BoofTesting.assertEquals(expected, found, 1e-4);
}
use of boofcv.abst.distort.FDistort in project BoofCV by lessthanoptimal.
the class TestDetectChessboardFiducial method renderTarget.
public GrayF32 renderTarget(int numRows, int numCols) {
GrayF32 gray = new GrayF32(w, h);
float backgroundValue = 150f;
float squareValue = 20f;
ImageMiscOps.fill(gray, backgroundValue);
int numCols2 = numCols / 2;
int numRows2 = numRows / 2;
numCols = numCols / 2 + numCols % 2;
numRows = numRows / 2 + numRows % 2;
// create the grid
for (int y = 0; y < numRows; y++) {
for (int x = 0; x < numCols; x++) {
int pixelY = 2 * y * squareLength + offsetY;
int pixelX = 2 * x * squareLength + offsetX;
ImageMiscOps.fillRectangle(gray, squareValue, pixelX, pixelY, squareLength, squareLength);
}
}
for (int y = 0; y < numRows2; y++) {
for (int x = 0; x < numCols2; x++) {
int pixelY = 2 * y * squareLength + offsetY + squareLength;
int pixelX = 2 * x * squareLength + offsetX + squareLength;
ImageMiscOps.fillRectangle(gray, squareValue, pixelX, pixelY, squareLength, squareLength);
}
}
if (transform != null) {
GrayF32 distorted = new GrayF32(gray.width, gray.height);
FDistort f = new FDistort(gray, distorted);
f.border(backgroundValue).affine(transform.c, -transform.s, transform.s, transform.c, transform.T.x, transform.T.y).apply();
gray = distorted;
}
if (showRendered) {
ShowImages.showWindow(gray, "Rendered");
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return gray;
}
Aggregations