简体   繁体   English

分析栅格图层的像素分布

[英]Analyse Pixel distribution of a Rasterlayer

I really really need some advice.我真的很需要一些建议。 I have a Raster with many pixels.我有一个有很多像素的光栅。 Each pixel has one value.每个像素都有一个值。 Now I want to do a spatial analysis of these pixels.现在我想对这些像素进行空间分析。 I want to see in which region have the most pixels and were not.我想看看哪个区域的像素最多而没有。 Sounds simple, but it's not.听起来很简单,但事实并非如此。

I had an idea to do this with the kernal density but it does not work with rasterlayer.我有一个想法用内核密度来做到这一点,但它不适用于光栅层。 It doesn't work either with ppp, because you can't transform a raster into this data type.它也不适用于 ppp,因为您无法将栅格转换为这种数据类型。 I'm really lost.我真的迷路了。 I don't know what could work.我不知道什么可以工作。 So I would be very grateful if I could get some help.因此,如果我能得到一些帮助,我将不胜感激。

My Pixels looks like this:我的像素看起来像这样:
像素

There must be a way to show the regions with the most pixels and so on.必须有一种方法来显示像素最多的区域等等。 But I don't know how I can do that.但我不知道我该怎么做。

Short answer : convert your raster object to a pixel image of class im in the spatstat package.简短回答:将您的光栅对象转换为spatstat包中im类的像素图像。 Then use Smooth.im .然后使用Smooth.im Example:例子:

library(spatstat)
Z <- as.im(my_raster_data)
S <- Smooth(Z)
plot(S)

Long answer : you're using the term "pixel" in a nonstandard sense.长答案:您在非标准意义上使用术语“像素”。 The pixels are the small squares which make up the image.像素是构成图像的小方块。 Your illustration shows a pixel image in which the majority of the pixels have the value 0 (represented by white colour), but a substantial number of individual pixels have values greater than 0 (ranging from 0 to 0.3).您的插图显示了一个像素图像,其中大多数像素的值为 0(由白色表示),但大量单个像素的值大于 0(范围从 0 到 0.3)。

If I understand correctly, you would like to generate a colour image or heat map which has a brighter/warmer colour in those places where more of the pixels have positive values.如果我理解正确,您想在更多像素具有正值的地方生成颜色更亮/更暖的彩色图像或热图。

The simplest way is to use Gaussian smoothing of the pixel values in the image.最简单的方法是对图像中的像素值使用高斯平滑。 This will calculate a spatially-varying average of the values of the nearby pixels, including the zero pixels.这将计算附近像素值的空间变化平均值,包括零像素。 To do this, convert the raster to a pixel image of class im in the spatstat package为此,请将光栅转换为spatstat包中im类的像素图像

Z <- as.im(my_raster_object)

then apply Smooth.im然后应用Smooth.im

S <- Smooth(Z)
plot(S)

Look at the help for Smooth.im for options to control the degree of smoothing.查看Smooth.im的帮助以了解控制平滑程度的选项。

If you wanted to ignore the actual colours (pixel values) in the input data, you could just transform them to binary values before smoothing:如果您想忽略输入数据中的实际颜色(像素值),您可以在平滑之前将它们转换为二进制值:

B <- (Z > 0)
SB <- Smooth(B)
plot(SB)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM