Translate

2019年9月11日水曜日

findMaxima (MaximumFinder)で解析範囲を指定する-1

とても久しぶりに更新。
輝点検出に便利なfindMaxima。JavaではMaximumFinderクラスを使う。
コンストラクタは、シンプルにMaximumFinderのみ。
MaximumFinder mf = new MaximumFinder()
輝点検出には、主にgetMaximaか、findMaximaを使う。
java.awt.Polygon getMaxima(ImageProcessor ip, double tolerance, boolean excludeOnEdges)

ByteProcessor findMaxima(ImageProcessor ip, double tolerance, int outputType, boolean excludeOnEdges)
findMaximaの方は、outputTypeにMaximumFinder.Maskなどとしておけば、Mask画像を返してくれる。getMaximaの方は、輝点をPointRoiとして利用したい場合に便利。Polygonとしてもらっておけば、例えば、
poly = mf.getMaxima(ip, tolerance, false);

PointRoi pr = new PointRoi(poly.xpoints, poly.ypoints, poly.npoints);

imp.setRoi(pr);
とすれば、検出した輝点をPointRoiとして表示してくれる。

さて、画面全体に対して輝点検出する場合はこれでよいが、例えば画面の一部分ROIで区切った個所だけを検出することができると、MaximumFinderの説明文に書いてある。

Except for segmentation, this plugin works with area ROIs, including non-rectangular ROIs, which define the area where maxima are reported.

円形のROIを設定することにする。getMaximaの引数がImageProcessor ipなので、
ip.setRoi(ovalRoi);
poly = mf.getMaxima(ip, tolerance, false);
とでもすれば、 指定できるのかと思いきやうまくいかない。円なのに矩形領域になってしまう。
じゃあ、ImagePlusに指定すればいいのかと思い、
imp.setRoi(ovalRaoi);
としてもダメ。ImageJの掲示板に似たような議論があったが、ip.setRoiでうまくいくよ、と書いてあるけどうまくいかない。
discrepancy between APi and IJ.run in Find maxima

こういう時は、MaximumFinderのソースコードを見る必要がある。
MaximumFinder.java
例えば、上記のgetMaximaを見てみると、
public Polygon getMaxima(ImageProcessor ip, double tolerance, boolean excludeOnEdges) {
return getMaxima(ip, tolerance, excludeOnEdges, excludeOnEdges);}
public Polygon getMaxima(ImageProcessor ip, double tolerance, boolean strict, boolean excludeOnEdges) {
 findMaxima(ip, tolerance, strict, ImageProcessor.NO_THRESHOLD,
  MaximumFinder.POINT_SELECTION, excludeOnEdges, false);
 if (xyCoordinates==null)
  return new Polygon();
 else
return xyCoordinates;}
となっており、結局findMaximaを呼んでいることがわかる。
2へ続く

0 件のコメント:

コメントを投稿