本文整理汇总了Java中org.openimaj.image.MBFImage.getBand方法的典型用法代码示例。如果您正苦于以下问题:Java MBFImage.getBand方法的具体用法?Java MBFImage.getBand怎么用?Java MBFImage.getBand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openimaj.image.MBFImage
的用法示例。
在下文中一共展示了MBFImage.getBand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateIntensityNTSC
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Calculate intensity by a weighted average of the R, G, B planes. Assumes
* planes are all in the same magnitude, and NTSC weighting coefficients.
*
* @param in
* MBFImage with 3 bands
* @return intensity image
*/
public static FImage calculateIntensityNTSC(final MBFImage in) {
if (in.colourSpace != ColourSpace.RGB && in.colourSpace != ColourSpace.RGBA)
throw new UnsupportedOperationException("Can only convert RGB or RGBA images");
final FImage out = new FImage(in.getWidth(), in.getHeight());
for (int r = 0; r < in.getHeight(); r++) {
for (int c = 0; c < in.getWidth(); c++) {
out.pixels[r][c] = (0.299f * in.getBand(0).pixels[r][c] +
0.587f * in.getBand(1).pixels[r][c] +
0.114f * in.getBand(2).pixels[r][c]);
}
}
return out;
}
示例2: 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;
}
示例3: 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;
}
示例4: calculateIntensityNTSC_LUT
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Calculate intensity by a weighted average of the R, G, B planes. Assumes
* planes are all in 0..1, and NTSC weighting coefficients. Assignment to
* graylevels is done using a LUT, so greys will have one of 256 discrete
* levels. The primary purpose of this is to be compatible with
* {@link FImage#FImage(int[], int, int)} and give exactly the same result.
*
* @param in
* MBFImage with 3 bands
* @return intensity image
*/
public static FImage calculateIntensityNTSC_LUT(final MBFImage in) {
if (in.colourSpace != ColourSpace.RGB && in.colourSpace != ColourSpace.RGBA)
throw new UnsupportedOperationException("Can only convert RGB or RGBA images");
final FImage out = new FImage(in.getWidth(), in.getHeight());
for (int r = 0; r < in.getHeight(); r++) {
for (int c = 0; c < in.getWidth(); c++) {
out.pixels[r][c] = ImageUtilities.BYTE_TO_FLOAT_LUT[(int) ((
0.299f * (255 * in.getBand(0).pixels[r][c]) +
0.587f * (255 * in.getBand(1).pixels[r][c]) +
0.114f * (255 * in.getBand(2).pixels[r][c])))];
}
}
return out;
}
示例5: calculateIntensity
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Calculate intensity by averaging R, G, B planes. Assumes planes are all
* in the same magnitude.
*
* @param in
* MBFImage with 3 bands
* @return intensity image
*/
public static FImage calculateIntensity(final MBFImage in) {
if (in.colourSpace != ColourSpace.RGB && in.colourSpace != ColourSpace.RGBA)
throw new UnsupportedOperationException("Can only convert RGB or RGBA images");
final FImage out = new FImage(in.getWidth(), in.getHeight());
for (int r = 0; r < in.getHeight(); r++) {
for (int c = 0; c < in.getWidth(); c++) {
out.pixels[r][c] = (in.getBand(0).pixels[r][c] +
in.getBand(1).pixels[r][c] +
in.getBand(2).pixels[r][c]) / 3.0F;
}
}
return out;
}
示例6: H_TO_H1H2_2
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Convert to Hue to H2 VARIANT 2 using the formulation from:
* http://ilab.usc.edu/wiki/index.php/HSV_And_H2SV_Color_Space
*
* @param in
* Hue image
* @return H1H2_2 image
*/
public static MBFImage H_TO_H1H2_2(final FImage in) {
final int width = in.getWidth();
final int height = in.getHeight();
final MBFImage out = new MBFImage(width, height, ColourSpace.H1H2_2);
final float[][] H = in.pixels;
final float[][] H1 = out.getBand(0).pixels;
final float[][] H2 = out.getBand(1).pixels;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (H[y][x] > 0.3333333333F)
{
H2[y][x] = ((H[y][x] - 0.3333333333F) / 0.6666666666F);
if (H[y][x] > 0.6666666666F)
H1[y][x] = ((H[y][x] - 0.6666666666F) / 0.5F);
else
H1[y][x] = (1 - (H[y][x] - 0.1666666666F) / 0.5F);
}
else
{
H2[y][x] = (1 - H[y][x] / 0.3333333333F);
if (H[y][x] > 0.1666666666F)
H1[y][x] = (1 - (H[y][x] - 0.1666666666F) / 0.5F);
else
H1[y][x] = ((2.0F / 3.0F) + H[y][x] / 0.5F);
}
}
}
return out;
}
示例7: 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;
}
示例8: RGB_TO_HSV
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Convert to HSV using the formulation from:
* http://ilab.usc.edu/wiki/index.php/HSV_And_H2SV_Color_Space The
* assumption is that RGB are in the range 0..1. H is output in the range
* 0..1, SV are output in the range 0..1
*
* @param in
* RGB or RGBA image
* @return HSV image
*/
public static MBFImage RGB_TO_HSV(final MBFImage in) {
if (in.colourSpace != ColourSpace.RGB && in.colourSpace != ColourSpace.RGBA)
throw new IllegalArgumentException("RGB or RGBA colourspace is required");
final int width = in.getWidth();
final int height = in.getHeight();
final MBFImage out = new MBFImage(width, height, ColourSpace.HSV);
final float[][] R = in.getBand(0).pixels;
final float[][] G = in.getBand(1).pixels;
final float[][] B = in.getBand(2).pixels;
final float[][] H = out.getBand(0).pixels;
final float[][] S = out.getBand(1).pixels;
final float[][] V = out.getBand(2).pixels;
final float[] pIn = new float[3];
final float[] pOut = new float[3];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
pIn[0] = R[y][x];
pIn[1] = G[y][x];
pIn[2] = B[y][x];
Transforms.RGB_TO_HSV(pIn, pOut);
H[y][x] = pOut[0];
S[y][x] = pOut[1];
V[y][x] = pOut[2];
}
}
return out;
}
示例9: process
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
public FImage process(byte[] img) throws IOException {
MBFImage toRet = ImageUtilities.readMBF(new ByteArrayInputStream(img));
if (ct != null)
toRet = ct.convert(toRet);
return toRet.getBand(band);
}
示例10: read
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
public MBFImage read(byte[] record) {
final MBFImage image = new MBFImage(width, height, ColourSpace.RGB);
final float[][] r = image.getBand(0).pixels;
final float[][] g = image.getBand(1).pixels;
final float[][] b = image.getBand(2).pixels;
for (int y = 0, j = 0; y < height; y++) {
for (int x = 0; x < width; x++, j++) {
r[y][x] = ImageUtilities.BYTE_TO_FLOAT_LUT[record[j] & 0xff];
g[y][x] = ImageUtilities.BYTE_TO_FLOAT_LUT[record[j + height * width] & 0xff];
b[y][x] = ImageUtilities.BYTE_TO_FLOAT_LUT[record[j + 2 * height * width] & 0xff];
}
}
return image;
}
示例11: analyseImage
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
public void analyseImage(MBFImage image) {
final int width = image.getWidth();
final int height = image.getHeight();
image = ColourSpace.convert(image, ColourSpace.RGB);
final FImage r = image.getBand(0);
final FImage g = image.getBand(1);
final FImage b = image.getBand(2);
double avgr = 0;
double avgg = 0;
double avgb = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
avgr += r.pixels[y][x];
avgg += g.pixels[y][x];
avgb += b.pixels[y][x];
}
}
avgr /= (width * height);
avgg /= (width * height);
avgb /= (width * height);
contrast = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
final double deltar = r.pixels[y][x] - avgr;
final double deltag = g.pixels[y][x] - avgg;
final double deltab = b.pixels[y][x] - avgb;
contrast += (deltar * deltar) + (deltag * deltag) + (deltab * deltab);
}
}
contrast /= (height * width);
}
示例12: H_TO_H1H2
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Convert to Hue to H2 using the formulation from:
* http://ilab.usc.edu/wiki/index.php/HSV_And_H2SV_Color_Space
*
* @param in
* input image
* @return Two-component hue image
*/
public static MBFImage H_TO_H1H2(final FImage in) {
final int width = in.getWidth();
final int height = in.getHeight();
final MBFImage out = new MBFImage(width, height, ColourSpace.H1H2);
final float[][] H = in.pixels;
final float[][] H1 = out.getBand(0).pixels;
final float[][] H2 = out.getBand(1).pixels;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (H[y][x] > 0.5F)
{
H2[y][x] = ((H[y][x] - 0.5F) / 0.5F);
if (H[y][x] > 0.75)
H1[y][x] = ((H[y][x] - 0.75F) / 0.5F);
else
H1[y][x] = (1 - (H[y][x] - 0.25F) / 0.5F);
}
else
{
H2[y][x] = (1F - H[y][x] / 0.5F);
if (H[y][x] > 0.25F)
H1[y][x] = (1 - (H[y][x] - 0.25F) / 0.5F);
else
H1[y][x] = (0.5F + H[y][x] / 0.5F);
}
}
}
return out;
}
示例13: processFrame
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
public MBFImage processFrame(MBFImage frame) {
addToCache(frame);
final int height = frame.getHeight();
final float prop = (float) (cacheSize) / height;
frame.fill(RGBColour.BLACK);
final float[][] framer = frame.getBand(0).pixels;
final float[][] frameg = frame.getBand(1).pixels;
final float[][] frameb = frame.getBand(2).pixels;
for (int y = 0; y < height; y++) {
final int index = (int) (y * prop);
if (index >= cache.size()) {
break;
}
// System.out.println("y = " + y);
// System.out.println("index = " + index);
final float[][][] cacheImage = cache.get(index);
System.arraycopy(cacheImage[0][y], 0, framer[y], 0, cacheImage[0][y].length);
System.arraycopy(cacheImage[1][y], 0, frameg[y], 0, cacheImage[1][y].length);
System.arraycopy(cacheImage[2][y], 0, frameb[y], 0, cacheImage[2][y].length);
}
for (final FImage f : frame.bands) {
FImageConvolveSeparable.convolveVertical(f, blurKern);
}
if (cache.size() >= cacheSize)
cache.removeLast();
return frame;
}
示例14: 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]++;
}
}
}
示例15: H2SV_TO_HSV_Simple
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* Convert H2SV to HSV VARIANT 1 using the simple formulation from:
* http://ilab.usc.edu/wiki/index.php/HSV_And_H2SV_Color_Space Assumes H1
* and H2 are 0..1. Output H is 0..1
*
* @param in
* H2SV image
* @return HSV image
*/
public static MBFImage H2SV_TO_HSV_Simple(final MBFImage in)
{
final MBFImage out = new MBFImage(in.getWidth(), in.getHeight(), ColourSpace.HSV);
final float[][] H = out.getBand(0).pixels;
final float[][] H1 = in.getBand(0).pixels;
final float[][] H2 = in.getBand(1).pixels;
final int width = in.getWidth();
final int height = in.getHeight();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (H1[y][x] > 0.5)
if (H2[y][x] > 0.5)
H[y][x] = 0.5f * H1[y][x] - 0.25f;
else
H[y][x] = 0.25f + 0.5f * (1f - H1[y][x]);
else if (H2[y][x] <= 0.5)
H[y][x] = 0.25f + 0.5f * (1f - H1[y][x]);
else
H[y][x] = 0.75f + 0.5f * H1[y][x];
}
}
out.addBand(in.getBand(2)); // S
out.addBand(in.getBand(3)); // V
return out;
}