本文整理汇总了Java中org.openimaj.image.MBFImage.numBands方法的典型用法代码示例。如果您正苦于以下问题:Java MBFImage.numBands方法的具体用法?Java MBFImage.numBands怎么用?Java MBFImage.numBands使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openimaj.image.MBFImage
的用法示例。
在下文中一共展示了MBFImage.numBands方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertColours
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Convert the colour space of an image, maintaining three bands so it can
* be displayed
*
* @param frame
* @param colourSpace
*/
public static void convertColours(MBFImage frame, ColourSpace colourSpace) {
// update the frame from the camera by converting to the selected colour
// space before display
final MBFImage cvt = colourSpace.convert(frame);
// if the converted image has fewer than 3 bands, add more so it can be
// displayed as RGB.
if (cvt.numBands() == 1) {
// this makes a three-band grey-level image, where all the bands are
// the same
cvt.bands.add(cvt.getBand(0).clone());
cvt.bands.add(cvt.getBand(0).clone());
} else if (cvt.numBands() == 2) {
// this adds a third zero band to a two-band image
cvt.bands.add(new FImage(cvt.getWidth(), cvt.getHeight()));
}
// this sets the frame to the colour converted version
frame.internalAssign(cvt);
}
示例2: extract
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
public FeatureVector extract(MBFImage image, FImage mask) {
MBFImage converted = converter.convert(image);
if (converted.numBands() != bins.size()) {
throw new RuntimeException("Incorrect number of dimensions - recieved " + bins.size() +", expected " + converted.numBands() +".");
}
int [] ibins = new int[bins.size()];
for (int i=0; i<bins.size(); i++)
ibins[i] = bins.get(i);
BlockHistogramModel hm = null;
if (mask == null)
hm = new BlockHistogramModel(blocks_x, blocks_y, ibins);
else
hm = new MaskingBlockHistogramModel(mask, blocks_x, blocks_y, ibins);
hm.estimateModel(converted);
return hm.toSingleHistogram();
}
示例3: imageToVector
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
protected float[][] imageToVector(MBFImage image) {
final int height = image.getHeight();
final int width = image.getWidth();
final int bands = image.numBands();
final float[][] f = new float[height * width][bands + 2];
for (int b = 0; b < bands; b++) {
final float[][] band = image.getBand(b).pixels;
final float w = scaling == null ? 1 : scaling[b];
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
f[x + y * width][b] = band[y][x] * w;
}
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
f[x + y * width][bands] = ((float) x / (float) width) * (scaling == null ? 1 : scaling[bands]);
f[x + y * width][bands + 1] = ((float) y / (float) height) * (scaling == null ? 1 : scaling[bands + 1]);
}
}
return f;
}
示例4: imageToVector
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
protected float[][] imageToVector(MBFImage image) {
final int height = image.getHeight();
final int width = image.getWidth();
final int bands = image.numBands();
final float[][] f = new float[height * width][bands];
for (int b = 0; b < bands; b++) {
final float[][] band = image.getBand(b).pixels;
final float w = scaling == null ? 1 : scaling[b];
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
f[x + y * width][b] = band[y][x] * w;
}
return f;
}
示例5: crop
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Returns an image containing just the connected component cropped from the
* original image. Although that the result image is necessarily
* rectangular, the pixels which are not part of the connected component
* will be transparent.
*
* @param input
* The input image from which to take the pixels
* @param blackout
* Whether to blackout pixels that are not part of the region or
* whether to mark them as transparent
* @return An image with the component's pixels cropped
*/
public MBFImage crop(MBFImage input, boolean blackout) {
final Rectangle bb = this.calculateRegularBoundingBox();
final MBFImage output = new MBFImage((int) bb.width, (int) bb.height, input.numBands());
for (int y = 0; y < (int) bb.height; y++) {
for (int x = 0; x < (int) bb.width; x++) {
for (int b = 0; b < input.numBands(); b++) {
if (!blackout || this.pixels.contains(new Pixel(x + (int) bb.x, y + (int) bb.y)))
output.getBand(b).setPixel(x, y, input.getBand(b).getPixel(x + (int) bb.x, y + (int) bb.y));
else
output.getBand(b).setPixel(x, y, 0f);
}
}
}
return output;
}
示例6: gistGabor
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
private FloatFV gistGabor(MBFImage img) {
final int blocksPerFilter = computeNumberOfSamplingBlocks();
final int nFeaturesPerBand = gaborFilters.length * blocksPerFilter;
final int nFilters = this.gaborFilters.length;
// pad the image
img = img.paddingSymmetric(boundaryExtension, boundaryExtension, boundaryExtension, boundaryExtension);
final int cols = img.getCols();
final int rows = img.getRows();
final FloatFFT_2D fft = new FloatFFT_2D(rows, cols);
final float[][] workingSpace = new float[rows][cols * 2];
final FloatFV fv = new FloatFV(nFeaturesPerBand * img.numBands());
for (int b = 0; b < img.numBands(); b++) {
final FImage band = img.bands.get(b);
final float[][] preparedImage =
FourierTransform.prepareData(band.pixels, rows, cols, true);
fft.complexForward(preparedImage);
for (int i = 0; i < nFilters; i++) {
// convolve with the filter
FImage ig = performConv(fft, preparedImage, workingSpace, this.gaborFilters[i], rows, cols);
// remove padding
ig = ig.extractROI(boundaryExtension, boundaryExtension, band.width - 2 * boundaryExtension, band.height
- 2
* boundaryExtension);
sampleResponses(ig, fv.values, b * nFeaturesPerBand + i * blocksPerFilter);
}
}
return fv;
}
示例7: extract
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
private float[][] extract(MBFImage image, Line2d line, int numSamples) {
final float[][] samples = new float[image.numBands()][];
for (int i = 0; i < image.numBands(); i++) {
samples[i] = sampler.extractSamples(line, image.getBand(i), numSamples);
}
return samples;
}
示例8: extractNormalisedStacked
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Extract normalised stacked samples b1b1b1bb2b2b2b3b3b3...
*
* @param image
* @param line
* @return
*/
private float[] extractNormalisedStacked(MBFImage image, Line2d line) {
final float[] samples = new float[nsamples * image.numBands()];
for (int i = 0; i < image.numBands(); i++) {
final float[] s = sampler.extractSamples(line, image.getBand(i), nsamples);
System.arraycopy(s, 0, samples, i * nsamples, nsamples);
}
return normaliseSamples(samples);
}
示例9: accum
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
protected void accum(MBFImage im) {
if (im.numBands() != ndims)
throw new AssertionError("number of bands must match");
for (int y=0; y<im.getHeight(); y++) {
for (int x=0; x<im.getWidth(); x++) {
if (mask.pixels[y][x] != 1)
continue;
int [] bins = new int[ndims];
for (int i=0; i<ndims; i++) {
bins[i] = (int)(im.getBand(i).pixels[y][x] * (histogram.nbins[i]));
if (bins[i] >= histogram.nbins[i]) bins[i] = histogram.nbins[i] - 1;
}
int bin = 0;
for (int i=0; i<ndims; i++) {
int f = 1;
for (int j=0; j<i; j++)
f *= histogram.nbins[j];
bin += f * bins[i];
}
histogram.values[bin]++;
}
}
}
示例10: accum
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
protected void accum(MBFImage im) {
final int height = im.getHeight();
final int width = im.getWidth();
final int[] bins = new int[ndims];
final float[][][] bands = new float[im.numBands()][][];
for (int i = 0; i < bands.length; i++)
bands[i] = im.getBand(i).pixels;
final int[] nbins = histogram.nbins;
final double[] values = histogram.values;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
for (int i = 0; i < ndims; i++) {
bins[i] = (int) (bands[i][y][x] * (nbins[i]));
if (bins[i] >= nbins[i])
bins[i] = nbins[i] - 1;
}
int bin = 0;
for (int i = 0; i < ndims; i++) {
int f = 1;
for (int j = 0; j < i; j++)
f *= nbins[j];
bin += f * bins[i];
}
values[bin]++;
}
}
}
示例11: RGB_TO_HSL
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Transform 3 band RGB image to HSL
*
* @param in
* RGB or RGBA image
* @return HSL image
*/
public static MBFImage RGB_TO_HSL(final MBFImage in) {
if (in.colourSpace != ColourSpace.RGB && in.colourSpace != ColourSpace.RGBA)
throw new IllegalArgumentException("RGB or RGBA colourspace is required");
final MBFImage out = in.clone();
final float[] pix = new float[in.numBands()];
for (int y = 0; y < in.getHeight(); y++) {
for (int x = 0; x < in.getWidth(); x++) {
for (int b = 0; b < in.numBands(); b++)
pix[b] = in.getBand(b).pixels[y][x];
Transforms.RGB_TO_HSL(pix, pix);
for (int b = 0; b < in.numBands(); b++)
out.getBand(b).pixels[y][x] = pix[b];
}
}
// final MBFImage out = Transforms.RGB_TO_HSV(in);
//
// final FImage R = in.getBand(0);
// final FImage G = in.getBand(1);
// final FImage B = in.getBand(2);
//
// final FImage L = out.getBand(2);
// for (int y = 0; y < L.height; y++) {
// for (int x = 0; x < L.width; x++) {
// final float max = Math.max(Math.max(R.pixels[y][x], G.pixels[y][x]),
// B.pixels[y][x]);
// final float min = Math.min(Math.min(R.pixels[y][x], G.pixels[y][x]),
// B.pixels[y][x]);
// L.pixels[y][x] = 0.5f * (max - min);
// }
// }
out.colourSpace = ColourSpace.HSL;
return out;
}
示例12: extractPixels1d
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Extract a 1xarea image with all the pixels from the region in it. Useful
* for analysing the colour for example
*
* @param input
* input image to extract samples from
* @return new image with pixels set from samples
*/
public MBFImage extractPixels1d(MBFImage input) {
final MBFImage out = new MBFImage(pixels.size(), 1, input.numBands());
int j = 0;
for (final Pixel p : pixels) {
for (int i = 0; i < input.numBands(); i++) {
out.setPixel(j, 0, input.getPixel(p.x, p.y));
}
j++;
}
return out;
}
示例13: inpaint
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
protected void inpaint(int x, int y, MBFImage input) {
final int width = input.getWidth();
final int height = input.getHeight();
final float gradx_u = gradX(timeMap.pixels, x, y);
final float grady_u = gradY(timeMap.pixels, x, y);
final int nbands = input.numBands();
final float accum[] = new float[nbands];
float norm = 0;
for (final Pixel p : region) {
final int xx = p.x + x;
final int yy = p.y + y;
if (xx <= 1 || xx >= width - 1 || yy <= 1 || yy >= height - 1)
continue;
if (flag[yy][xx] != KNOWN)
continue;
final int rx = x - xx;
final int ry = y - yy;
// geometric distance.
final float geometricDistance = (float) (1. / ((rx * rx + ry * ry) * Math.sqrt((rx * rx + ry * ry))));
// levelset distance.
final float levelsetDistance = (float) (1. / (1 + Math.abs(timeMap.pixels[yy][xx] - timeMap.pixels[y][x])));
// Dot product of final displacement and gradient vectors.
float direction = Math.abs(rx * gradx_u + ry * grady_u);
if (direction < 0.000001f)
direction = 0.000001f;
final float weight = geometricDistance * levelsetDistance * direction;
for (int i = 0; i < nbands; i++)
accum[i] += weight * input.getBand(i).pixels[yy][xx];
norm += weight;
}
for (int i = 0; i < nbands; i++)
input.getBand(i).pixels[y][x] = accum[i] / norm;
}
示例14: colourTemperatureCorrection
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Correct colour temperature using the method documented at Tanner Helland.
* Calculated the black body colour for the given temperature and alpha
* blends that with a constant luminance with the original image at the
* given strength. Only works on RGB images. Side affects the incoming
* image.
*
* @param image
* @param colourTemperature
* The colour temperature.
* @param strength
* The strength of colour correction
*
* @see "http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/"
* @return The affected image.
*/
public static MBFImage colourTemperatureCorrection(final MBFImage image,
final double colourTemperature, final double strength)
{
if (image.colourSpace != ColourSpace.RGB)
throw new IllegalArgumentException("Colour correction only available for RGB images. " +
"Try using the colour transforms to convert to RGB.");
// Get the black body colour for the given temperature.
final double rgb[] = Transforms.kelvinToRGB(colourTemperature);
final float[] pix = new float[image.numBands()];
final float[] oPix = new float[image.numBands()];
for (int y = 0; y < image.getHeight(); y++)
{
for (int x = 0; x < image.getWidth(); x++)
{
for (int b = 0; b < image.numBands(); b++)
{
float f = image.getBand(b).pixels[y][x];
oPix[b] = f;
f = (float) (f * strength + rgb[b] * (1f - strength));
pix[b] = f;
}
// pix contains the alpha blended original pixels. Calculate HSL
Transforms.RGB_TO_HSL(pix, pix);
// subsititue the luminance of original pixels
pix[2] = (ArrayUtils.maxValue(oPix) + ArrayUtils.minValue(oPix)) / 2f;
// Transform back to RGB
Transforms.HSL_TO_RGB(pix, pix);
for (int b = 0; b < image.numBands(); b++)
image.getBand(b).pixels[y][x] = pix[b];
}
}
return image;
}
示例15: drawImage
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Draw the provided image at the given coordinates. Parts of the image
* outside the bounds of this image will be ignored
*
* @param image
* Image to draw.
* @param x
* x-coordinate
* @param y
* y-coordinate
*/
@Override
public void drawImage(final MBFImage image, final int x, final int y) {
final int targetBands = this.targetImage.numBands();
final int imageBands = image.numBands();
if (targetBands == imageBands && targetBands == 3) {
this.drawImage3(image, x, y);
return;
} else if (targetBands < 3 || targetBands > 4 || imageBands < 3 || imageBands > 4) {
super.drawImage(image, x, y);
return;
}
final int stopx = Math.min(this.targetImage.getWidth(), x + image.getWidth());
final int stopy = Math.min(this.targetImage.getHeight(), y + image.getHeight());
final int startx = Math.max(0, x);
final int starty = Math.max(0, y);
final float[][][] thisPixels = new float[targetBands][][];
for (int i = 0; i < thisPixels.length; i++)
thisPixels[i] = this.targetImage.getBand(i).pixels;
final float[][][] thatPixels = new float[imageBands][][];
for (int i = 0; i < thatPixels.length; i++)
thatPixels[i] = image.getBand(i).pixels;
/**
* If either image is 4 channel then we deal with the alpha channel
* correctly. Basically you add together the pixel values such that the
* pixel on top dominates (i.e. the image being added)
*/
// final float thisA = 1.0f, thatA = 1.0f, thisR, thisG, thisB, thatR, thatG, thatB, a, r, g, b;
if(thisPixels.length == 4 && thatPixels.length == 4){
drawBothAlpha(x, y, stopx, stopy, startx, starty, thisPixels, thatPixels);
} else if (thisPixels.length == 4){
drawThisAlpha(x, y, stopx, stopy, startx, starty, thisPixels, thatPixels);
} else{
drawThatAlpha(x, y, stopx, stopy, startx, starty, thisPixels, thatPixels);
}
}