Guest User

Untitled

a guest
Dec 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. package com.example;
  2.  
  3. import net.imagej.ImageJ;
  4. import net.imagej.ops.deconvolve.RichardsonLucyF;
  5. import net.imagej.ops.filter.convolve.ConvolveFFTF;
  6. import net.imglib2.Point;
  7. import net.imglib2.RandomAccessibleInterval;
  8. import net.imglib2.algorithm.region.hypersphere.HyperSphere;
  9. import net.imglib2.img.Img;
  10. import net.imglib2.img.array.ArrayImgFactory;
  11. import net.imglib2.outofbounds.OutOfBoundsConstantValueFactory;
  12. import net.imglib2.type.NativeType;
  13. import net.imglib2.type.numeric.RealType;
  14. import net.imglib2.type.numeric.real.FloatType;
  15. import net.imglib2.util.Util;
  16. import net.imglib2.view.IntervalView;
  17. import net.imglib2.view.Views;
  18.  
  19. /**
  20. * Tests involving convolvers.
  21. */
  22. public class DeconvolveTest {
  23.  
  24. public static <T extends RealType<T> & NativeType<T>> void main(
  25. final String[] args)
  26. {
  27.  
  28. // create an instance of imagej
  29. final ImageJ ij = new ImageJ();
  30.  
  31. // launch it
  32. ij.launch(args);
  33.  
  34. int[] size = new int[] { 225, 167 };
  35.  
  36. // create an input with a small sphere at the center
  37. Img<FloatType> in = new ArrayImgFactory<FloatType>().create(size,
  38. new FloatType());
  39.  
  40. placeSphereInCenter(in);
  41.  
  42. // crop the image so the sphere is truncated at the corner
  43. // (this is useful for testing non-circulant mode)
  44. IntervalView<FloatType> incropped = Views.interval(in, new long[] {
  45. size[0] / 2, size[1] / 2 }, new long[] { size[0] - 1, size[1] - 1 });
  46.  
  47. incropped = Views.zeroMin(incropped);
  48.  
  49. ij.ui().show(incropped);
  50.  
  51. RandomAccessibleInterval<FloatType> kernel = ij.op().create().kernelGauss(
  52. new double[] { 7.0, 7.0 }, new FloatType());
  53.  
  54. // convolve
  55. @SuppressWarnings("unchecked")
  56. final Img<FloatType> convolved = (Img<FloatType>) ij.op().run(
  57. ConvolveFFTF.class, incropped, kernel);
  58.  
  59. @SuppressWarnings("unchecked")
  60. final Img<FloatType> convolved2 = (Img<FloatType>) ij.op().run(
  61. ConvolveFFTF.class, in, kernel);
  62.  
  63. ij.ui().show("convolved", convolved);
  64.  
  65. @SuppressWarnings("unchecked")
  66. final RandomAccessibleInterval<FloatType> deconvolved =
  67. (RandomAccessibleInterval<FloatType>) ij.op().run(RichardsonLucyF.class,
  68. convolved, kernel, null, new OutOfBoundsConstantValueFactory<>(Util
  69. .getTypeFromInterval(in).createVariable()), 100);
  70.  
  71. @SuppressWarnings("unchecked")
  72. final RandomAccessibleInterval<FloatType> deconvolved2 =
  73. (RandomAccessibleInterval<FloatType>) ij.op().run(RichardsonLucyF.class,
  74. convolved, kernel, null, new OutOfBoundsConstantValueFactory<>(Util
  75. .getTypeFromInterval(in).createVariable()), null, null, null, 100,
  76. true, false);
  77.  
  78. @SuppressWarnings("unchecked")
  79. final RandomAccessibleInterval<FloatType> deconvolved3 =
  80. (RandomAccessibleInterval<FloatType>) ij.op().run(RichardsonLucyF.class,
  81. convolved2, kernel, null, new OutOfBoundsConstantValueFactory<>(Util
  82. .getTypeFromInterval(in).createVariable()), 100);
  83.  
  84. @SuppressWarnings("unchecked")
  85. final RandomAccessibleInterval<FloatType> deconvolved4 =
  86. (RandomAccessibleInterval<FloatType>) ij.op().run(RichardsonLucyF.class,
  87. convolved2, kernel, null, new OutOfBoundsConstantValueFactory<>(Util
  88. .getTypeFromInterval(in).createVariable()), null, null, null, 100,
  89. true, false);
  90.  
  91. ij.ui().show("deconvolved", deconvolved);
  92. ij.ui().show("deconvolved-nc", deconvolved2);
  93. ij.ui().show("deconvolved", deconvolved3);
  94. ij.ui().show("deconvolved-nc", deconvolved4);
  95.  
  96. }
  97.  
  98. // utility to place a small sphere at the center of the image
  99. static private void placeSphereInCenter(Img<FloatType> img) {
  100.  
  101. final Point center = new Point(img.numDimensions());
  102.  
  103. for (int d = 0; d < img.numDimensions(); d++)
  104. center.setPosition(img.dimension(d) / 2, d);
  105.  
  106. HyperSphere<FloatType> hyperSphere = new HyperSphere<>(img, center, 30);
  107.  
  108. for (final FloatType value : hyperSphere) {
  109. value.setReal(1000);
  110. }
  111. }
  112. }
Add Comment
Please, Sign In to add comment