weixin_39878698
2020-12-09 09:22 阅读 1

Threshold function

First of all, very nice package! Regeratablly I din't find other contact details, so I have to use the forum.

Is it possible to see the value of the threshold when using the threshold function? Normally the threshold is only applied to the image, without any information which threshold is choosen.

More over, is there any possibility to see the code of threshold function?

Best wishes and thanks in advance, Norman

该提问来源于开源项目:dahtah/imager

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

8条回答 默认 最新

  • weixin_39986543 weixin_39986543 2020-12-09 09:22

    You can get the threshold value. The example code is shown below.

    
    library(imager)
    im 

    You can see the code of threshold function. https://github.com/dahtah/imager/blob/b8f3724f024bb9af993bd01f37e0080d0f35ecf0/R/utils.R#L418-L453

    点赞 评论 复制链接分享
  • weixin_39878698 weixin_39878698 2020-12-09 09:22

    Dear ShotaOchi,

    thanks for your fast and good reply.

    Regrettably this only works with classical images and not for raster images. The main reason for using the imager package was that it also can handle raster images.

    Applying your code to a raster resulting in this error:

    thr <- max(Raster * (1 - b)) Warning message: In max(new("RasterLayer", file = new(".RasterFile", name = "", datanotation = "FLT4S", : Nothing to summarize if you provide a single RasterLayer; see cellStats

    点赞 评论 复制链接分享
  • weixin_39986543 weixin_39986543 2020-12-09 09:22

    Just coerce raster objects into cimg objects.

    ras as.cimg(ras) * (1 - as.cimg(b))) # thr is the threshold value
    
    点赞 评论 复制链接分享
  • weixin_39878698 weixin_39878698 2020-12-09 09:22

    Hey ShotaOchi,

    Sorry for border you again, but there are still problems in this code.

    First, when you need the adjust function for the threshold code, you will not get this value from the code above.

    Moreover, the thr value (thr) is all the time 0 by applying your code, independent from the input.

    Thanks in advance for your kind support, Norman

    点赞 评论 复制链接分享
  • weixin_39986543 weixin_39986543 2020-12-09 09:22

    I don't understand what is the adjust function for the threshold code.

    The above code worked fine on my machine when I input a raster object shown below.

    
    ras1 

    The above code didn't work on my machine when I input a raster object shown below. threshold(ras2) returned the error message 'Error in storage.mode(x) <- "double" :'.

    
    ras2 

    I can't reproduce your problem.

    Moreover, the thr value (thr) is all the time 0 by applying your code, independent from the input.

    What raster object did you input?

    点赞 评论 复制链接分享
  • weixin_39633054 weixin_39633054 2020-12-09 09:22

    The adjust argument works similarly to the adjust argument in R's density function: it adjusts the automatic threshold up or down, i.e. if the auto threshold is 3.1 and adj=2 the threshold will actually be 6.2. It's just for convenience.

    点赞 评论 复制链接分享
  • weixin_39878698 weixin_39878698 2020-12-09 09:22

    Yes, the first part is completly correct and I also know.

    So if understand your post correctly, you have to multiply the threshold value with the adjust value? as Example:

    Adjust= 0.5 thr * 0.5

    adjust = 1.5 thr * 1.5

    点赞 评论 复制链接分享
  • weixin_39986543 weixin_39986543 2020-12-09 09:22

    thr in the above code is same as below. https://github.com/dahtah/imager/blob/b8f3724f024bb9af993bd01f37e0080d0f35ecf0/R/utils.R#L433 So, We don't have to myltiply the threshold value with the adjust value.

    点赞 评论 复制链接分享

相关推荐