【问题标题】:Why this regionprops returns 0x1 struct?为什么这个 regionprops 返回 0x1 结构?
【发布时间】:2016-06-28 11:52:39
【问题描述】:

我正在尝试将 wiki 页面 here 中 MIT 的 course Biological Instrumentation and Measurement 的代码从 Matlab 7.3 转换为 Matlab R2016a。 我的输入数据的特征是平方 L2 范数的规模。 高斯核应该使用平方 L2 范数,但我发现 Matlab 和 Octave 中的高斯函数之间存在显着差异,请参阅答案here。 该代码是关于从 PSF 幻灯片图像估计分辨率以及关于函数 EstimateResolutionFromPsfImage,在 Matlab 2016a 中默认值为 tolarance [0.7 1.3]

resolutionEstimate = EstimateResolutionFromPsfImage(im2bw(imgRGB), [0.7 1.3]); 

imgRGB 在哪里

由于命令从 EstimateResolutionFromPsfImage 的第 29 行返回 objectProperties 中的 0x1 结构

,因此输出导致复杂化
objectProperties = regionprops( dilatedImage, ImageData, ...
    'Area', 'Centroid', 'PixelList', 'PixelValues', 'MaxIntensity' );

我不明白在这种情况下它如何为零。 我的工作区一开始还可以,但是在通过objecProperties 语句后,有一个 0x1 结构,它不应该几乎是空的

并最终导致错误

Index exceeds matrix dimensions.

Error in EstimateResolutionFromPsfImage (line 108)
    Resolution = mean( allPeakData(:,4) ) ./ 0.336;

Error in masi (line 272)
resolutionEstimate = EstimateResolutionFromPsfImage(im2bw(imgRGB), [0.7 1.3]);

可能的原因

  • 输入。 ImageData 可能是错误的。
  • 更改为regionprops。我认为regionprops 中有些东西我还不够了解。 命令imagesc(dilatedImage) 显示矩阵dilatedImage 为空,即矩阵中的每个单元格都为空,如Shai cmets。 这证实了问题在于objectProperties,因为dilatedImage 依赖于objectProperties,它是0x1 结构,即导致复杂化。
  • 从 Matlab 7.3 到 2016a 的转换。我在代码中没有发现任何只有 Matlab 7.3 独有的东西。它应该适用于 Matlab 2016a,就像 Matlab 7.3 一样。

基于 dhanushka 提示的 Psf 图像生成

麻省理工学院的代码SimulatePsfSlide 似乎在生成psfImg 时以某种方式起作用。 我正在审查不同参数对结果的影响并确认结果,但在曝光过度的图像方面遇到了一些困难,最终会出现类似警告

Warning: Rank deficient, rank = 4, tol =  1.979466e-12. 
> In nlinfit>LMfit (line 579)
  In nlinfit (line 276)
...
Warning: Rank deficient, rank = 1, tol =  1.979466e-12. 
Warning: Some columns of the Jacobian are effectively zero at the solution,
indicating that the model is insensitive to some of its parameters.  That may be
because those parameters are not present in the model, or otherwise do not
affect the predicted values.  It may also be due to numerical underflow in the
model function, which can sometimes be avoided by choosing better initial
parameter values, or by rescaling or recentering.  Parameter estimates may be
unreliable. 

这里有些行会导致并发症,我不明白为什么要使用 16 以及为什么要使用 im2double 进行转换

simulatedPsfImage = im2double( simulatedPsfImage * 16 );

Matlab 2016a 中 dhanushka 的代码

当图像不是 PSF(如第一张图像)时,Matlab 无法处理同质变化的输入。

不推荐使用 Dhanushka 的过滤器here,原因很多。 我用代码得到了一个更好的模型,具有更大的容差(甚至是 1.00)。用更好的过滤器替换 dhanushka 的不推荐过滤器并使用它

im = im2double( imgGray ); % zeros( ImageSize ) );
sigma = 5;
simulatedPsfImage = imgaussfilt(im, sigma); 
simulatedPsfImage = im2double( simulatedPsfImage );
[ measuredResolution, standardError, bestFitData ] = ...
    EstimateResolutionFromPsfImage( simulatedPsfImage, [1.00 1.00] ); 

输出更好

BestFitData = 249.999999999989 249.999999999989 0.00713504020178639 5.31607106546232 -0.000392450463696062;所以估计Sigma = 5.316,比dhanushka的第二个例子差。 在 Matlab 中,fspecial gaussian 的容差水平会出现严重问题,但在 Octave 中则不会,如 dhanushka 的第二个示例所示。

火星延伸

Mars case 输入时带有 dhanushka 的代码

imgaussfilt 输出

最终结论

L2 范数在这里是不够的。


为什么这里regionprops的输出是0x1 struct?

【问题讨论】:

  • 这意味着dilatedImage 是空的 - 它全为零,其中没有对象。尝试imagesc(dilatedImage) 并检查它。
  • 我不知道为什么。您必须调试 EstimateResolutionFromPsfImage 函数以查看 dilatedImage 是如何计算的。
  • 据我了解,您的输入图像不是 PSF 图像。在您提供的链接中,有一个函数 (SimulatePsfSlide) 可以生成 PSF 图像进行测试。
  • 您一遍又一遍地更改问题,试图为您的 整个项目/练习 获得结果。到这个时候,您应该已经知道 SO 不是来制作您的项目的。你不能问“如何做这整件事”,每次有人帮助你解决一个新问题时就去更新它。

标签: matlab image-processing struct


【解决方案1】:

据我了解,您的输入图像不是 PSF 图像。引用您提供的link,PSF 图像是暗背景上近似点源的图像,例如星域或亚分辨率荧光微球。您可以使用给定代码中的SimulatePsfSlide 函数生成此类图像以进行测试。

编辑

我没有 Matlab。我用一个简单的 PSF 图像在 Octave 中运行代码,在下面的代码生成的图像中间有一个单点源。您可以先尝试使用简单的已知图像并检查结果。

在下面的代码中,您可以改变高斯 PSF 大小和 sigma,并查看 nlinfit 如何估计 sigma。

过度曝光应该不是问题,这些值是根据链接中的测试代码剪辑的。

 clear all
 close all

 psfSize = 9;
 psfSigma = 5;

 % single point source in the middle: this is the object
 ImageSize = [500 500];
 im = im2double( zeros( ImageSize ) );
 im( int32(ImageSize(1)/2), int32(ImageSize(2)/2) ) = 1;
 % gaussian psf: this is the psf of our imaging system
 h = fspecial('gaussian', [psfSize psfSize], psfSigma);
 % convolve the object with psf: the image, this is what we see
 simulatedPsfImage = imfilter(im, h, 'same');
 simulatedPsfImage = im2double( simulatedPsfImage );
 % estimating resolution
 [ measuredResolution, standardError, bestFitData ] = ...
        EstimateResolutionFromPsfImage( simulatedPsfImage );

输入数据和nlinfit 输出(仅限 beta 和 MSE):请注意,在第二种情况下,MSE 较小,表明输入数据与模型非常匹配。我们也得到了正确的 sigma。

psfSize = 9,sigma = 5,估计 sigma = 3.0730

beta = 
2.5000e+002
2.5000e+002
2.0275e-002
3.0730e+000
-4.4688e-004

mse =   1.6114e-006

psfSize = 25,sigma = 5,估计 sigma = 5.0000

beta = 
2.5000e+002
2.5000e+002
6.5254e-003
5.0000e+000
7.3796e-010

mse =   2.2996e-020

在 Matlab 2016a 中输出 psfSize=9psfSigma=5,这表明在 Matlab 和 Octave 中 fspecial 之间存在显着差异

bestFitData = 250.000000000593 250.000000000593 0.0202577533025840 3.07726724108174 -0.000451857701021258;这里估计Sigma = 3.077。

【讨论】:

  • @Masi 是什么让您认为第一个图中的同质图像是 PSF? (提示:这不是它不起作用的原因)
  • @Masi 从您的编辑中,我感觉您误解了我发布的代码,因此我添加了一些说明。我并不是建议您首先使用高斯滤波器对输入图像进行平滑处理。我只是给出了一个使用合成 psf 图像的简单示例(不使用 SimulatePsfSlide)。合成图像模拟是理想的情况。还要仔细阅读 EstimateResolutionFromPsfImage 中的 cmets。某些图像可能需要稍作修改。真实图像远非理想。
  • @Masi 你可以通过观察nlinfit的其他输出参数来定量地检查差异。该代码仅使用估计的模型参数(或 beta)。
  • @Masi 我不认为你需要 Octave,它似乎不像 Matlab 那样提供有用的警告信息。例如,当我尝试将模型拟合到大多数不合适的数据时,我没有收到来自 nlinfit 的任何警告。我将为上述每种情况添加 MSE 值。其他参数是相当大的向量/矩阵。
  • EstimatedSigma 为 5.316,在 Matlab 中为 imgaussfilt,但在 fspecial 中为 3.077。您是如何要求估计的 Sigma 在 Octave 中保持为 5 的?
猜你喜欢
  • 2021-12-17
  • 2012-12-17
  • 1970-01-01
  • 1970-01-01
  • 2018-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多