本文整理汇总了Java中org.openimaj.image.colour.ColourSpace.convert方法的典型用法代码示例。如果您正苦于以下问题:Java ColourSpace.convert方法的具体用法?Java ColourSpace.convert怎么用?Java ColourSpace.convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openimaj.image.colour.ColourSpace
的用法示例。
在下文中一共展示了ColourSpace.convert方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertColours
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的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: doTutorial
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的package包/类
@Override
public void doTutorial(MBFImage toDraw) {
final MBFImage space = ColourSpace.convert(toDraw, ColourSpace.CIE_Lab);
if (cluster == null)
cluster = clusterPixels(space);
if (cluster == null)
return;
final float[][] centroids = cluster.getCentroids();
final ExactFloatAssigner assigner = new ExactFloatAssigner(cluster);
for (int y = 0; y < space.getHeight(); y++) {
for (int x = 0; x < space.getWidth(); x++) {
final float[] pixel = space.getPixelNative(x, y);
final int centroid = assigner.assign(pixel);
space.setPixelNative(x, y, centroids[centroid]);
}
}
toDraw.internalAssign(ColourSpace.convert(space, ColourSpace.RGB));
}
示例3: makeDisparityMap
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的package包/类
/**
* Compute the disparity map between two images. If the images
* are not in Lab colour space, then copies in lab space will
* be created.
* @param im1 The first image.
* @param im2 The second image.
* @return the disparity map between the colours in the two images.
*/
public static FImage makeDisparityMap(MBFImage im1, MBFImage im2) {
if (im1.colourSpace != ColourSpace.CIE_Lab) {
im1 = ColourSpace.convert(im1, ColourSpace.CIE_Lab);
}
if (im2.colourSpace != ColourSpace.CIE_Lab) {
im2 = ColourSpace.convert(im2, ColourSpace.CIE_Lab);
}
FImage disparity = new FImage(im1.getWidth(), im1.getHeight());
for (int y=0; y<disparity.height; y++) {
for (int x=0; x<disparity.width; x++) {
disparity.pixels[y][x] = calculateDeltaE(im1.getPixel(x, y), im2.getPixel(x, y));
}
}
return disparity;
}
示例4: segment
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的package包/类
@Override
public List<? extends PixelSet> segment(final MBFImage image) {
final MBFImage input = ColourSpace.convert(image, colourSpace);
final float[][] imageData = imageToVector(input);
final FloatCentroidsResult result = kmeans.cluster(imageData);
final List<PixelSet> out = new ArrayList<PixelSet>(kmeans.getConfiguration().getK());
for (int i = 0; i < kmeans.getConfiguration().getK(); i++)
out.add(new PixelSet());
final HardAssigner<float[], ?, ?> assigner = result.defaultHardAssigner();
final int height = image.getHeight();
final int width = image.getWidth();
for (int y = 0, i = 0; y < height; y++) {
for (int x = 0; x < width; x++, i++) {
final float[] pixel = imageData[i];
final int centroid = assigner.assign(pixel);
out.get(centroid).addPixel(x, y);
}
}
return out;
}
示例5: main
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
HistogramModel model = new HistogramModel(16, 16, 16);
MBFImage im = ImageUtilities.readMBF(new File("/Users/jsh2/Pictures/08-earth_shuttle2.jpg"));
im = ColourSpace.convert(im, ColourSpace.CIE_Lab);
im.bands.get(0).divideInplace(100F);
im.bands.get(1).subtractInplace(-127F).divideInplace(256F);
im.bands.get(2).subtractInplace(-127F).divideInplace(256F);
System.out.println(im.bands.get(2));
/* ERROR HERE */
model.estimateModel(im);
double[] arr1 = model.histogram.values.clone();
im = ImageUtilities.readMBF(new File("/Users/jsh2/Pictures/08-earth_shuttle2.jpg"));
im = ColourSpace.convert(im, ColourSpace.CIE_Lab_Norm);
model.estimateModel(im);
double[] arr2 = model.histogram.values.clone();
System.out.println(Arrays.toString(arr1));
System.out.println(Arrays.toString(arr2));
System.out.println(Arrays.equals(arr1, arr2));
}
示例6: analyseImage
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的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);
}
示例7: analyseImage
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的package包/类
@Override
public void analyseImage(MBFImage image) {
final List<ConnectedComponent> ccs = segmenter.segment(image);
final MBFImage labImage = ColourSpace.convert(image, ColourSpace.CIE_Lab);
final float[][] avgs = new float[ccs.size()][3];
final int w = image.getWidth();
final int h = image.getHeight();
// calculate patch average colours
for (int i = 0; i < avgs.length; i++) {
for (final Pixel p : ccs.get(i).pixels) {
final Float[] v = labImage.getPixel(p);
avgs[i][0] += v[0];
avgs[i][0] += v[1];
avgs[i][0] += v[2];
}
final int sz = ccs.get(i).pixels.size();
avgs[i][0] /= sz;
avgs[i][1] /= sz;
avgs[i][2] /= sz;
}
for (int i = 0; i < avgs.length; i++) {
for (int j = i + 1; j < avgs.length; j++) {
final PixelSet ci = ccs.get(i);
final PixelSet cj = ccs.get(i);
final float C = CIEDE2000.calculateDeltaE(avgs[i], avgs[j]);
contrast += (1 - distance(ci, cj, w, h)) * (C / (ci.calculateArea() * cj.calculateArea()));
}
}
}
示例8: testRGBtoRGBA
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的package包/类
/**
* @throws Exception
*/
@Test
public void testRGBtoRGBA() throws Exception {
final MBFImage img = ImageUtilities.readMBF(ColourSpaceTest.class
.getResourceAsStream("/org/openimaj/image/data/sinaface.jpg"));
final MBFImage imgConv = ColourSpace.convert(img, ColourSpace.RGBA);
assertTrue(img.getBounds().equals(imgConv.getBounds()));
assertTrue(img.equals(ColourSpace.convert(imgConv, ColourSpace.RGB)));
}
示例9: main
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的package包/类
/**
* Main method
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// Load the image
MBFImage input = ImageUtilities.readMBF(new URL("http://static.openimaj.org/media/tutorial/sinaface.jpg"));
input = ColourSpace.convert(input, ColourSpace.CIE_Lab);
final FloatKMeans cluster = FloatKMeans.createExact(3, 2);
final float[][] imageData = input.getPixelVectorNative(new float[input.getWidth() * input.getHeight()][3]);
final FloatCentroidsResult result = cluster.cluster(imageData);
final float[][] centroids = result.centroids;
for (final float[] fs : centroids) {
System.out.println(Arrays.toString(fs));
}
final HardAssigner<float[], ?, ?> assigner = result.defaultHardAssigner();
for (int y = 0; y < input.getHeight(); y++) {
for (int x = 0; x < input.getWidth(); x++) {
final float[] pixel = input.getPixelNative(x, y);
final int centroid = assigner.assign(pixel);
input.setPixelNative(x, y, centroids[centroid]);
}
}
input = ColourSpace.convert(input, ColourSpace.RGB);
DisplayUtilities.display(input);
final GreyscaleConnectedComponentLabeler labeler = new GreyscaleConnectedComponentLabeler();
final List<ConnectedComponent> components = labeler.findComponents(input.flatten());
int i = 0;
for (final PixelSet comp : components) {
if (comp.calculateArea() < 50)
continue;
input.drawText("Point:" + (i++), comp.calculateCentroidPixel(), HersheyFont.TIMES_MEDIUM, 20);
}
DisplayUtilities.display(input);
}
示例10: analyseImage
import org.openimaj.image.colour.ColourSpace; //导入方法依赖的package包/类
@Override
public void analyseImage(MBFImage image) {
int width = image.getWidth();
int height = image.getHeight();
MBFImage lab = ColourSpace.convert(image, ColourSpace.CIE_Lab);
float[][] Lb = lab.getBand(0).pixels;
float[][] ab = lab.getBand(1).pixels;
float[][] bb = lab.getBand(2).pixels;
float mL = 0, ma = 0, mb = 0;
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
mL += Lb[y][x];
ma += ab[y][x];
mb += bb[y][x];
}
}
mL /= (height*width);
ma /= (height*width);
mb /= (height*width);
//blur
MBFImage blur = lab.process(new FGaussianConvolve(sigma));
Lb = blur.getBand(0).pixels;
ab = blur.getBand(1).pixels;
bb = blur.getBand(2).pixels;
//create map
map = new FImage(width, height);
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
float dL = (Lb[y][x]-mL);
float da = (ab[y][x]-ma);
float db = (bb[y][x]-mb);
map.pixels[y][x] = dL*dL + da*da + db*db;
}
}
map.normalise();
}