use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ExamplePlanarImages method independent.
/**
* Many operations designed to only work on {@link ImageGray} can be applied
* to a Planar image by feeding in each band one at a time.
*/
public static void independent(BufferedImage input) {
// convert the BufferedImage into a Planar
Planar<GrayU8> image = ConvertBufferedImage.convertFromPlanar(input, null, true, GrayU8.class);
// declare the output blurred image
Planar<GrayU8> blurred = image.createSameShape();
// Apply Gaussian blur to each band in the image
for (int i = 0; i < image.getNumBands(); i++) {
// note that the generalized version of BlurImageOps is not being used, but the type
// specific version.
BlurImageOps.gaussian(image.getBand(i), blurred.getBand(i), -1, 5, null);
}
// Declare the BufferedImage manually to ensure that the color bands have the same ordering on input
// and output
BufferedImage output = new BufferedImage(image.width, image.height, input.getType());
ConvertBufferedImage.convertTo(blurred, output, true);
gui.addImage(input, "Input");
gui.addImage(output, "Gaussian Blur");
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class UtilOpenKinect method bufferRgbToMsU8.
/**
* Converts ByteBuffer that contains RGB data into a 3-channel Planar image
* @param input Input buffer
* @param output Output depth image
*/
public static void bufferRgbToMsU8(ByteBuffer input, Planar<GrayU8> output) {
GrayU8 band0 = output.getBand(0);
GrayU8 band1 = output.getBand(1);
GrayU8 band2 = output.getBand(2);
int indexIn = 0;
for (int y = 0; y < output.height; y++) {
int indexOut = output.startIndex + y * output.stride;
for (int x = 0; x < output.width; x++, indexOut++) {
band0.data[indexOut] = input.get(indexIn++);
band1.data[indexOut] = input.get(indexIn++);
band2.data[indexOut] = input.get(indexIn++);
}
}
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ImplConvertJCodecPicture method yuv420_to_PlRgb_U8.
public static void yuv420_to_PlRgb_U8(Picture input, Planar<GrayU8> output) {
int[] Y = input.getPlaneData(0);
int[] U = input.getPlaneData(1);
int[] V = input.getPlaneData(2);
GrayU8 R = output.getBand(0);
GrayU8 G = output.getBand(1);
GrayU8 B = output.getBand(2);
final int yStride = output.width;
final int uvStride = output.width / 2;
for (int row = 0; row < output.height; row++) {
int indexY = row * yStride;
int indexUV = (row / 2) * uvStride;
int indexOut = output.startIndex + row * output.stride;
for (int col = 0; col < output.width; col++, indexOut++) {
int y = 1191 * (Y[indexY++] & 0xFF) - 16;
int cr = (U[indexUV] & 0xFF) - 128;
int cb = (V[indexUV] & 0xFF) - 128;
if (y < 0)
y = 0;
int b = (y + 1836 * cr) >> 10;
int g = (y - 547 * cr - 218 * cb) >> 10;
int r = (y + 2165 * cb) >> 10;
if (r < 0)
r = 0;
else if (r > 255)
r = 255;
if (g < 0)
g = 0;
else if (g > 255)
g = 255;
if (b < 0)
b = 0;
else if (b > 255)
b = 255;
R.data[indexOut] = (byte) r;
G.data[indexOut] = (byte) g;
B.data[indexOut] = (byte) b;
indexUV += col & 0x1;
}
}
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ImplConvertJCodecPicture method RGB_to_PLU8.
/**
* Converts a picture in JCodec RGB into RGB BoofCV
*/
public static void RGB_to_PLU8(Picture input, Planar<GrayU8> output) {
if (input.getColor() != ColorSpace.RGB)
throw new RuntimeException("Unexpected input color space!");
if (output.getNumBands() != 3)
throw new RuntimeException("Unexpected number of bands in output image!");
output.reshape(input.getWidth(), input.getHeight());
int[] dataIn = input.getData()[0];
GrayU8 out0 = output.getBand(0);
GrayU8 out1 = output.getBand(1);
GrayU8 out2 = output.getBand(2);
int indexIn = 0;
int indexOut = 0;
for (int i = 0; i < output.height; i++) {
for (int j = 0; j < output.width; j++, indexOut++) {
int r = dataIn[indexIn++];
int g = dataIn[indexIn++];
int b = dataIn[indexIn++];
out2.data[indexOut] = (byte) r;
out1.data[indexOut] = (byte) g;
out0.data[indexOut] = (byte) b;
}
}
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class JCodecSimplified method getGuiImage.
@Override
public <InternalImage> InternalImage getGuiImage() {
Planar<GrayU8> boofColor = new Planar<>(GrayU8.class, frameCurrent.getWidth(), frameCurrent.getHeight(), 3);
BufferedImage output = new BufferedImage(boofColor.width, boofColor.height, BufferedImage.TYPE_INT_RGB);
UtilJCodec.convertToBoof(frameCurrent, boofColor);
ConvertBufferedImage.convertTo(boofColor, output, true);
return (InternalImage) output;
}
Aggregations