为什么这个regionprops返回0x1 struct? [英] Why this regionprops returns 0x1 struct?

查看:211
本文介绍了为什么这个regionprops返回0x1 struct?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试转换麻省理工学院的代码



输出导致复杂性来自命令返回0x1的​​事实 EstimateResolutionFromPsfImage

的第29行 objectProperties 中的struct

  objectProperties = regionprops(dilatedImage,ImageData,... 
'Area','Centroid','PixelList','PixelValues','MaxIntensity');

我不明白在这种情况下如何为零。
我的工作区在开始时没问题,但是在传递 objecProperties 语句之后,有一个0x1结构,它不应该在那里几乎是空的





并最终导致错误

 指数超出矩阵维度。 

EstimateResolutionFromPsfImage中的错误(第108行)
分辨率=平均值(allPeakData(:,4))./ 0.336;

masi中的错误(第272行)
resolutionEstimate = EstimateResolutionFromPsfImage(im2bw(imgRGB),[0.7 1.3]);

可能的原因




  • 输入。 ImageData 可能错误。

  • 更改 regionprops 。我认为在 regionprops 中有一些我无法理解的东西。
    命令 imagesc(dilatedImage)显示矩阵 dilatedImage 为空,即每个单元格为空矩阵,像Shai评论。
    这确认问题出在 objectProperties ,因为 dilatedImage 依赖于 objectProperties 这是0x1 struct,即导致复杂化。

  • 从Matlab 7.3到2016a的转换。我没有在代码中找到任何只对Matlab 7.3唯一的东西。它应该适用于Matlab 2016a,就像Matlab 7.3一样。



基于dhanushka提示的Psf图像生成



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

 警告:等级不足,等级= 4,tol = 1.979466e-12。 
>在nlinfit> LMfit(第579行)
在nlinfit(第276行)
...
警告:等级不足,等级= 1,tol = 1.979466e-12。
警告:雅可比行列的某些列在解决方案中实际上为零,
表示模型对其某些参数不敏感。这可能是
,因为模型中不存在这些参数,否则
不会影响预测值。这也可能是由于
模型函数中的数值下溢,有时可以通过选择更好的初始
参数值,或通过重新缩放或重新定位来避免。参数估计可能是
不可靠。

这里有一些导致复杂的行,我不明白为什么16以及为什么用<$ c $转换c> im2double

  simulatedPsfImage = im2double(simulatedPsfImage * 16); 



dhanushka在Matlab 2016a中的代码



Matlab当图像不是PSF时,与第一张图像一样,不能使用均匀变化的输入。



不建议使用Dhanushka的过滤器



其中 BestFitData = 249.999999999989 249.999999999989 0.00713504020178639 5.31607106546232 -0.000392450463696062 ;所以估计西格玛= 5.316,这比dhanushka的第二个例子更糟糕。
Matlab中的 fspecial gaussian 在容差级别方面存在严重问题,但在dhanushka的第二个示例中则不会出现Octave。



扩展到火星



输入时使用dhanushka代码的火星情况





输出 imgaussfilt





最终结论



L2规范在这里还不够。






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

解决方案

据我所知,您的输入图像不是PSF图像。引用您提供的



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 = 9 psfSigma = 5 ,显示了Matl中 fspecial 之间的显着差异ab和Octave





其中 bestFitData = 250.000000000593 250.000000000593 0.0202577533025840 3.07726724108174 -0.000451857701021258 ;这里估计西格玛= 3.077。


I am trying to convert the code of MIT's course Biological Instrumentation and Measurement in the wiki page here from Matlab 7.3 to Matlab R2016a. My input data's features are in the scale of square L2 norm. Gaussian kernel should be using the square L2 norm, but I see significant differences between Gaussian functions in Matlab and Octave, see the answer here. The code is about Estimating resolution from a PSF slide image and about the function EstimateResolutionFromPsfImage with default values of tolarance [0.7 1.3] in Matlab 2016a

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

where imgRGB is

Output results in complications coming from the fact that the command returns 0x1 struct in objectProperties from the line 29 of EstimateResolutionFromPsfImage

objectProperties = regionprops( dilatedImage, ImageData, ...
    'Area', 'Centroid', 'PixelList', 'PixelValues', 'MaxIntensity' );

where I do not understand how it can be zero in the case. My workspace is ok at start but after passing the objecProperties statement, there is a 0x1 struct which should not be there as almost empty

and eventually leads to errors

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]);

Possible reasons

  • Input. ImageData possible wrong.
  • Changes is regionprops. I think there are something that I have not understood enough well in regionprops. The command imagesc(dilatedImage) shows that the matrix dilatedImage is null i.e. every cell is null in the matrix, like Shai comments. This confirms that the problem is with objectProperties because dilatedImage is dependent on the objectProperties which is 0x1 struct i.e. causing the complication.
  • Conversion from Matlab 7.3 to 2016a. I did not find anything that is only unique for Matlab 7.3 in the code. It should work for Matlab 2016a like for Matlab 7.3.

Psf image generation based on dhanushka's hint

MIT's code SimulatePsfSlide seems to work somehow in generating psfImg. I am reviewing the effect of different parameters on the result and confirming the result but have some difficulties with overexposed images and and eventually having warnings like

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. 

Here some line which causes complications where I do not understand why 16 and why conversion with im2double

simulatedPsfImage = im2double( simulatedPsfImage * 16 );

dhanushka's code in Matlab 2016a

Matlab does not work with inputs of homogenous changes when the image is not PSF, like the first image.

Dhanushka's filter is not recommended here because of many reasons. I get a much better model with significantly greater tolerance (even 1.00) with the code. Replace dhanushka's not recommended filter by a better one and use this

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

Output is much better

where BestFitData = 249.999999999989 249.999999999989 0.00713504020178639 5.31607106546232 -0.000392450463696062; so estimatedSigma = 5.316, which is worser than dhanushka's second example. You will have significant problems with tolerance levels with the fspecial gaussian in Matlab, but not in Octave like dhanushka's second example shows.

Extension to Mars

Mars case with dhanushka's code when input

Output with imgaussfilt

Final conclusion

L2 norm is not sufficient here.


Why is the output of regionprops here 0x1 struct?

解决方案

To my understanding your input image isn't a PSF image. Quoting from the link you provided, a PSF image is an image of approximate point sources on a dark background, such as a star field or sub resolution fluorescent microspheres. You can generate such image for testing using the SimulatePsfSlide function in the given code.

EDIT

I don't have Matlab. I ran the code in Octave with a simple PSF image having a single point source in the middle of the image generated from the code below. You can first try with a simple known image and check the result.

In the code below, you can vary the Gaussian PSF size and sigma and see how nlinfit estimates the sigma.

Over-exposure shouldn't be a problem, those values are clipped according to the test code in the link.

 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 );

Input data and nlinfit output (beta and MSE only): Note that in the second case, the MSE is smaller, indicating that the input data closely matches the model. Also we get the correct sigma.

psfSize = 9, sigma = 5, estimated 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, estimated sigma = 5.0000

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

mse =   2.2996e-020

Output in Matlab 2016a with psfSize=9 and psfSigma=5, which shows a significant difference between fspecial in Matlab and Octave

where bestFitData = 250.000000000593 250.000000000593 0.0202577533025840 3.07726724108174 -0.000451857701021258; here estimatedSigma = 3.077.

这篇关于为什么这个regionprops返回0x1 struct?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆