本文整理汇总了Java中ij.process.FloatProcessor.duplicate方法的典型用法代码示例。如果您正苦于以下问题:Java FloatProcessor.duplicate方法的具体用法?Java FloatProcessor.duplicate怎么用?Java FloatProcessor.duplicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.process.FloatProcessor
的用法示例。
在下文中一共展示了FloatProcessor.duplicate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeMeanAndVariance
import ij.process.FloatProcessor; //导入方法依赖的package包/类
@Override
protected void makeMeanAndVariance(ByteProcessor I, Parameters params) {
FloatProcessor mean = (FloatProcessor) I.convertToFloat();
FloatProcessor var = (FloatProcessor) mean.duplicate();
RankFilters rf = new RankFilters();
rf.rank(mean, params.radius, RankFilters.MEAN);
Imean = mean;
rf.rank(var, params.radius, RankFilters.VARIANCE);
var.sqrt();
Isigma = var;
}
示例2: makeGradientsAndMagnitudeGray
import ij.process.FloatProcessor; //导入方法依赖的package包/类
private void makeGradientsAndMagnitudeGray(ImageProcessor I) {
FloatProcessor If = I.convertToFloatProcessor(); // always makes a copy
// apply a separable Gaussian filter to I
float[] gaussKernel = makeGaussKernel1d(params.gSigma);
Convolver conv = new Convolver();
conv.setNormalize(true);
conv.convolve(If, gaussKernel, gaussKernel.length, 1);
conv.convolve(If, gaussKernel, 1, gaussKernel.length);
// calculate the gradients in X- and Y-direction
Ex = If;
Ey = (FloatProcessor) If.duplicate();
float[] gradKernel = {-0.5f, 0, 0.5f};
conv.setNormalize(false);
conv.convolve(Ex, gradKernel, gradKernel.length, 1);
conv.convolve(Ey, gradKernel, 1, gradKernel.length);
Emag = new FloatProcessor(M, N);
float emax = 0;
for (int v = 0; v < N; v++) {
for (int u = 0; u < M; u++) {
float dx = Ex.getf(u,v);
float dy = Ey.getf(u,v);
float mag = (float) Math.hypot(dx, dy); // = (float) Math.sqrt(dx*dx + dy*dy);
if (mag > emax)
emax = mag;
Emag.setf(u, v, mag);
}
}
// normalize gradient magnitude
if (params.normGradMag && emax > 0.001)
Emag.multiply(100.0/emax);
}
示例3: imposeMinima
import ij.process.FloatProcessor; //导入方法依赖的package包/类
public static void imposeMinima(final FloatProcessor fp, final Roi roi) {
final ImageProcessor fpOrig = fp.duplicate();
// ImageStatistics stats = fp.getStatistics();
fp.setValue(Float.NEGATIVE_INFINITY);
fp.fill(roi);
ROILabeling.fillOutside(fp, roi, Float.POSITIVE_INFINITY);
fpOrig.copyBits(fp, 0, 0, Blitter.MIN);
fpOrig.multiply(-1);
fp.multiply(-1);
morphologicalReconstruction(fp, fpOrig);
fp.multiply(-1);
}
示例4: imposeMaxima
import ij.process.FloatProcessor; //导入方法依赖的package包/类
public static void imposeMaxima(final FloatProcessor fp, final ImageProcessor ipMask) {
final ImageProcessor fpOrig = fp.duplicate();
final ImageStatistics stats = fp.getStatistics();
final int w = fp.getWidth();
final int h = fp.getHeight();
for (int i = 0; i < w * h; i++) {
if (ipMask.getf(i) == 0)
fp.setf(i, Float.NEGATIVE_INFINITY);
else
fp.setf(i, Float.POSITIVE_INFINITY);
}
fpOrig.copyBits(fp, 0, 0, Blitter.MAX);
morphologicalReconstruction(fp, fpOrig);
for (int i = 0; i < w * h; i++) {
if (ipMask.getf(i) != 0)
fp.setf(i, (float)stats.max);
}
}
示例5: getThreshold
import ij.process.FloatProcessor; //导入方法依赖的package包/类
@Override
public ByteProcessor getThreshold(ByteProcessor I) {
FloatProcessor mean = (FloatProcessor) I.convertToFloat();
FloatProcessor var = (FloatProcessor) mean.duplicate();
RankFilters rf = new RankFilters();
rf.rank(mean, params.radius, RankFilters.MEAN);
Imean = mean;
rf.rank(var, params.radius, RankFilters.VARIANCE);
var.sqrt();
Isigma = var;
int width = I.getWidth();
int height = I.getHeight();
final double kappa = params.kappa;
final double sigmaMax = params.sigmaMax;
final boolean darkBg = (params.bgMode == BackgroundMode.DARK);
ByteProcessor Q = new ByteProcessor(width, height);
for (int v = 0; v < height; v++) {
for (int u = 0; u < width; u++) {
final double sigma = Isigma.getf(u, v);
final double mu = Imean.getf(u, v);
final double diff = kappa * (sigma / sigmaMax - 1);
int q = (int) Math.rint((darkBg) ? mu * (1 - diff) : mu * (1 + diff));
if (q < 0)
q = 0;
if (q > 255)
q = 255;
Q.set(u, v, q);
}
}
return Q;
}
示例6: gradientX
import ij.process.FloatProcessor; //导入方法依赖的package包/类
protected FloatProcessor gradientX(FloatProcessor fp) {
// Sobel-kernel for x-derivatives:
final float[] Hx = Matrix.multiply(1f/8, new float[] {
-1, 0, 1,
-2, 0, 2,
-1, 0, 1
});
FloatProcessor fpX = (FloatProcessor) fp.duplicate();
fpX.convolve(Hx, 3, 3);
return fpX;
}
示例7: gradientY
import ij.process.FloatProcessor; //导入方法依赖的package包/类
protected FloatProcessor gradientY(FloatProcessor fp) {
// Sobel-kernel for y-derivatives:
final float[] Hy = Matrix.multiply(1f/8, new float[] {
-1, -2, -1,
0, 0, 0,
1, 2, 1
});
FloatProcessor fpY = (FloatProcessor) fp.duplicate();
fpY.convolve(Hy, 3, 3);
return fpY;
}
示例8: process
import ij.process.FloatProcessor; //导入方法依赖的package包/类
/**
* Performs anisotropic diffusion. Makes <code>numberOfIterations</code> calls to {@link
* #diffuse(ij.process.FloatProcessor, ij.process.FloatProcessor)}, updating value of
* <code>time</code> before each call.
*
* @param src input image to which to apply anisotropic diffusion.
* @return result of anisotropic diffusion filtering.
*/
public FloatProcessor process(final FloatProcessor src) {
updateCurrentProgress(0, "");
FloatProcessor fp1 = (FloatProcessor) src.duplicate();
FloatProcessor fp2 = (FloatProcessor) src.duplicate();
for (int i = 0; i < numberOfIterations; i++) {
time = i * timeStep;
diffuse(fp1, fp2);
// swap
final FloatProcessor tmp = fp2;
fp2 = fp1;
fp1 = tmp;
// test change in images
final double mse = meanSquareDifference((float[]) fp1.getPixels(), (float[]) fp2.getPixels());
final String msg = "Iteration: " + i + ", mean square error: " + decimalFormat.format(mse);
updateCurrentProgress((double) (i + 1) / (double) numberOfIterations, msg);
IJDebug.log(msg);
if (mse <= meanSquareError) {
break;
}
}
updateCurrentProgress(1, "");
return fp1;
}
示例9: applyToolToImage
import ij.process.FloatProcessor; //导入方法依赖的package包/类
@Override
public Grid2D applyToolToImage(Grid2D imageProcessor) throws Exception {
FloatProcessor imp = new FloatProcessor(imageProcessor.getWidth(),imageProcessor.getHeight());
imp.setPixels(imageProcessor.getBuffer());
ImageProcessor imp1 = imp.duplicate(); // original
SimpleMatrix mat = config.getGeometry().getProjectionMatrix(imageIndex).computeP();
double [][] KinectDots3D = {{10, 10, 10}, {50, 50, 50}, {-20, -20, -20}}; // [beadNo][x,y,z]
double [] uv = new double[1];
for (int i=0; i< KinectDots3D.length; i++){
if (KinectDots3D[i][0] != 0 || KinectDots3D[i][1] != 0 || KinectDots3D[i][2] != 0){
uv = compute2DCoordinates(KinectDots3D[i], mat);
if (isDisplay) {
imp1.setValue(2);
imp1.drawLine((int) Math.round(uv[0]-10), (int) Math.round(uv[1]-10), (int) Math.round(uv[0]+10), (int) Math.round(uv[1]+10));
imp1.drawLine((int) Math.round(uv[0]-10), (int) Math.round(uv[1]+10), (int) Math.round(uv[0]+10), (int) Math.round(uv[1]-10));
}
}
}
if (isDisplay) {
for (int x=0; x< config.getGeometry().getDetectorWidth(); x+=100)
imp1.drawLine(x, 0, x, config.getGeometry().getDetectorHeight());
for (int y=0; y< config.getGeometry().getDetectorHeight(); y+=100)
imp1.drawLine(0, y, config.getGeometry().getDetectorWidth(), y);
}
Grid2D result = new Grid2D((float[]) imp1.getPixels(), imp1.getWidth(), imp1.getHeight());
return result;
}
示例10: applyToolToImage
import ij.process.FloatProcessor; //导入方法依赖的package包/类
@Override
public Grid2D applyToolToImage(Grid2D imageProcessor) {
FloatProcessor revan = new FloatProcessor(imageProcessor.getWidth(), imageProcessor.getHeight());
revan.setPixels(imageProcessor.getBuffer());
if (!twoD){
float [] kernel = designKernel(nTimes);
if (horizontal)
revan.convolve(kernel, kernel.length, 1);
else
revan.convolve(kernel, 1, kernel.length);
revan.multiply(0.5/Configuration.getGlobalConfiguration().getGeometry().getPixelDimensionX());
} else {
FloatProcessor xDerivative = (FloatProcessor) revan.duplicate();
xDerivative.convolve(designKernelX(), nTimes, nTimes);
xDerivative.multiply(0.5/Configuration.getGlobalConfiguration().getGeometry().getPixelDimensionX());
xDerivative.sqr();
FloatProcessor yDerivative = (FloatProcessor) revan.duplicate();
yDerivative.convolve(designKernelY(), nTimes, nTimes);
yDerivative.sqr();
yDerivative.multiply(0.5/Configuration.getGlobalConfiguration().getGeometry().getPixelDimensionY());
ImageUtil.addProcessors(xDerivative, yDerivative);
xDerivative.sqrt();
revan = xDerivative;
}
Grid2D result = new Grid2D((float[]) revan.getPixels(), revan.getWidth(), revan.getHeight());
return result;
}
示例11: makeGradientsAndMagnitudeColor
import ij.process.FloatProcessor; //导入方法依赖的package包/类
private void makeGradientsAndMagnitudeColor(ColorProcessor I) {
FloatProcessor[] Irgb = rgbToFloatChannels(I);
FloatProcessor[] Ixrgb = new FloatProcessor[3];
FloatProcessor[] Iyrgb = new FloatProcessor[3];
// apply a separable Gaussian filter to each RGB channel
float[] gaussKernel = makeGaussKernel1d(params.gSigma);
Convolver conv = new Convolver();
conv.setNormalize(true);
for (int i=0; i<Irgb.length; i++) {
FloatProcessor If = Irgb[i];
conv.convolve(If, gaussKernel, gaussKernel.length, 1);
conv.convolve(If, gaussKernel, 1, gaussKernel.length);
Ixrgb[i] = If;
Iyrgb[i] = (FloatProcessor) If.duplicate();
}
// calculate the gradients in X- and Y-direction for each RGB channel
float[] gradKernel = {-0.5f, 0, 0.5f};
conv.setNormalize(false);
for (int i = 0; i < Irgb.length; i++) {
FloatProcessor Ix = Ixrgb[i];
FloatProcessor Iy = Iyrgb[i];
conv.convolve(Ix, gradKernel, gradKernel.length, 1);
conv.convolve(Iy, gradKernel, 1, gradKernel.length);
}
// calculate gradient magnitude
Ex = new FloatProcessor(M, N);
Ey = new FloatProcessor(M, N);
Emag = new FloatProcessor(M, N);
float emax = 0;
for (int v = 0; v < N; v++) {
for (int u = 0; u < M; u++) {
float rx = Ixrgb[0].getf(u,v), ry = Iyrgb[0].getf(u,v);
float gx = Ixrgb[1].getf(u,v), gy = Iyrgb[1].getf(u,v);
float bx = Ixrgb[2].getf(u,v), by = Iyrgb[2].getf(u,v);
float A = rx*rx + gx*gx + bx*bx;
float B = ry*ry + gy*gy + by*by;
float C = rx*ry + gx*gy + bx*by;
float D = (float) Math.sqrt((A - B)*(A - B) + 4*C*C);
float mag = (float) Math.sqrt(0.5*(A+B+D));
if (mag > emax) emax = mag;
Emag.setf(u, v, mag);
Ex.setf(u, v, A - B + D);
Ey.setf(u, v, 2*C);
}
}
//IJ.log("RGB emax = " + emax);
// normalize gradient magnitude
if (params.normGradMag && emax > 0.001)
Emag.multiply(100.0/emax);
}
示例12: run
import ij.process.FloatProcessor; //导入方法依赖的package包/类
public FloatProcessor run(final FloatProcessor src) {
sizeX = src.getWidth();
sizeY = src.getHeight();
final FloatProcessor tmpSrc = (FloatProcessor) src.duplicate();
final FloatProcessor tmpDest = new FloatProcessor(sizeX, sizeY);
final GaussianSmoothFilter gaussianSmooth = new GaussianSmoothFilter();
for (int i = 1; i <= numberOfIterations; i++) {
// 1. compute the smoothed image
gaussianSmooth.setStandardDeviation(sigma);
// gaussianSmooth.setRadiusFactors(3.01, 3.01, 0);
smoothedImage = (FloatProcessor) gaussianSmooth.run(tmpSrc);
// 2. run iteration
iterate2D(tmpSrc, tmpDest);
copy(tmpDest, tmpSrc);
}
return tmpSrc;
}
示例13: run
import ij.process.FloatProcessor; //导入方法依赖的package包/类
public FloatProcessor run(final FloatProcessor src) {
final int width = src.getWidth();
final FloatProcessor dest = (FloatProcessor) src.duplicate();
final float[] srcPixels = (float[]) src.getPixels();
final float[] destPixels = (float[]) dest.getPixels();
final int xr = filterWidth / 2;
final int yr = filterHeight / 2;
final Rectangle roi = src.getRoi();
final int xMin = roi.x;
final int xMax = roi.x + roi.width;
final int yMin = roi.y;
final int yMax = roi.y + roi.height;
// Calculate increment, make sure that different/larger than 0 otherwise '%' operation will fail.
final int progressIncrement = Math.max((yMax - yMin) / 100, 1);
final float[] packet = new float[filterHeight];
for (int y = yMin; y < yMax; ++y) {
final int yOffset = y * width;
// Initialize median operator, with all but the last column in the structural key
operator.clear();
final int yyMin = Math.max(y - yr, yMin);
final int yyMax = Math.min(y + yr, yMax);
final int xxMin = xMin;
final int xxMax = Math.min(xMin + xr, xMax);
for (int xx = xxMin; xx < xxMax; ++xx) {
for (int yy = yyMin; yy < yyMax; ++yy) {
packet[yy - yyMin] = srcPixels[xx + yy * width];
}
operator.push(yyMax - yyMin, packet);
}
for (int x = xMin; x < xMax; ++x) {
if (x + xr < xMax) {
for (int yy = yyMin; yy < yyMax; ++yy) {
packet[yy - yyMin] = srcPixels[x + xr + yy * width];
}
operator.push(yyMax - yyMin, packet);
}
destPixels[x + yOffset] = operator.evaluate();
}
if (y % progressIncrement == 0) {
showProgress((double) (y - yMin) / (yMax - yMin));
}
}
hideProgress();
return dest;
}
示例14: detectMoleculeCandidates
import ij.process.FloatProcessor; //导入方法依赖的package包/类
/**
* Detection algorithm works simply by setting all values lower than a
* threshold to zero, splitting close peaks by watershed and finding
* centroids of connected components.
*
* In more detail this is how it is done:
* <ol>
* <li>apply the threshold to get thresholded binary image</li>
* <li>in the original image, set intensity to zero, where the thresholded
* image is zero. Leave the grayscale value otherwise.
* </li>
* <li>
* perform a watershed transform (this is the trick for recognition of more
* connected molecules
* </li>
* <li>AND the thresholded image with watershed image</li>
* <li>
* then we think of the resulting image as an undirected graph with
* 8-connectivity and find all connected components with the same id
* </li>
* <li>
* finally, positions of molecules are calculated as centroids of components
* with the same id
* </li>
* </ol>
*
* @param image an input image
* @return a {@code Vector} of {@code Points} containing positions of
* detected molecules
*/
@Override
public List<Point> detectMoleculeCandidates(FloatProcessor image) throws FormulaParserException {
//keep a local threshold value so the method remains thread safe
float localThresholdValue = Thresholder.getThreshold(threshold);
thresholdValue = localThresholdValue; //publish the calculated threshold,(not thread safe but only used for preview logging)
FloatProcessor thresholdedImage = (FloatProcessor) image.duplicate();
threshold(thresholdedImage, localThresholdValue, 0.0f, 255.0f);
FloatProcessor maskedImage = applyMask(image, thresholdedImage);
if(useWatershed) {
ImageJ_MaximumFinder watershedImpl = new ImageJ_MaximumFinder();
ByteProcessor watershedImage = watershedImpl.findMaxima(maskedImage, 0, ImageProcessor.NO_THRESHOLD, MaximumFinder.SEGMENTED, false, false);
FloatProcessor thresholdImageANDWatershedImage = applyMask(thresholdedImage, (FloatProcessor) watershedImage.convertToFloat());
maskedImage = thresholdImageANDWatershedImage;
}
// finding a center of gravity (with subpixel precision)
Vector<Point> detections = new Vector<Point>();
for(Graph.ConnectedComponent c : Graph.getConnectedComponents((ImageProcessor) maskedImage, Graph.CONNECTIVITY_8)) {
Point pt = c.centroid();
pt.val = new Double(image.getf((int)Math.round(pt.x.doubleValue()), (int)Math.round(pt.y.doubleValue())));
detections.add(pt);
}
return detections;
}
示例15: setImage
import ij.process.FloatProcessor; //导入方法依赖的package包/类
/**
* Set image to be segmented.
*
* @param image image.
*/
public void setImage(final FloatProcessor image) {
Validate.argumentNotNull(image, "image");
this.image = (FloatProcessor) image.duplicate();
}