- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一些图像要计算 Minkowski/box count dimension以确定图像中的分形特征。以下是 2 个示例图片:
10.jpg
:
24.jpg
:
我正在使用以下代码来计算分形维数:
import numpy as np
import scipy
def rgb2gray(rgb):
r, g, b = rgb[:,:,0], rgb[:,:,1], rgb[:,:,2]
gray = 0.2989 * r + 0.5870 * g + 0.1140 * b
return gray
def fractal_dimension(Z, threshold=0.9):
# Only for 2d image
assert(len(Z.shape) == 2)
# From https://github.com/rougier/numpy-100 (#87)
def boxcount(Z, k):
S = np.add.reduceat(
np.add.reduceat(Z, np.arange(0, Z.shape[0], k), axis=0),
np.arange(0, Z.shape[1], k), axis=1)
# We count non-empty (0) and non-full boxes (k*k)
return len(np.where((S > 0) & (S < k*k))[0])
# Transform Z into a binary array
Z = (Z < threshold)
# Minimal dimension of image
p = min(Z.shape)
# Greatest power of 2 less than or equal to p
n = 2**np.floor(np.log(p)/np.log(2))
# Extract the exponent
n = int(np.log(n)/np.log(2))
# Build successive box sizes (from 2**n down to 2**1)
sizes = 2**np.arange(n, 1, -1)
# Actual box counting with decreasing size
counts = []
for size in sizes:
counts.append(boxcount(Z, size))
# Fit the successive log(sizes) with log (counts)
coeffs = np.polyfit(np.log(sizes), np.log(counts), 1)
return -coeffs[0]
I = rgb2gray(scipy.misc.imread("24.jpg"))
print("Minkowski–Bouligand dimension (computed): ", fractal_dimension(I))
根据我读过的文献,有人建议自然场景(例如 24.jpg
)本质上更分形,因此应该有更大的分形维数值
它给我的结果与文献建议的方向相反:
10.jpg
:1.259
24.jpg
:1.073
我希望自然图像的分形维数比城市图像大
我在代码中计算的值是否错误?或者我只是错误地解释了结果?
最佳答案
对于物理事物的分形维度,该维度可能会在不同阶段收敛到不同的值。例如,一条非常细的线(但宽度有限)最初看起来是一维的,然后最终变成二维的,因为它的宽度变得与所使用的框的大小相当。
你看到了什么?那么线性拟合不是很好。维度正朝着二的方向发展。要进行诊断,让我们看一下生成的灰度图像,以及您拥有的阈值(即 0.9):
大自然的画面几乎成了一团墨迹。正如图表告诉我们的那样,维度很快就会达到 2 的值。那是因为我们几乎失去了形象。现在阈值为 50?
有了更好的新线性拟合,城市和自然的维度分别为 1.6 和 1.8。请记住,城市图片实际上有很多结构,特别是在有纹理的墙壁上。
将来好的阈值会更接近灰度图像的平均值,这样您的图像就不会变成一团墨水!
迈克尔·巴恩斯利 (Michael F. Barnsley) 的“无处不在的分形”是一本很好的教科书。
关于Python分形盒计数——分形维数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44793221/
我正在尝试创建带有固定三 Angular 形导航的网页。 问题是我无法将较小的三 Angular 形放入大三 Angular 形中,如下图所示。 当调整窗口大小时三 Angular 形正在改变它的 A
我目前正在使用 Angular-material,但我在另一个项目中遇到了一种情况,迫使我使用类似 angular material chips 的东西。效果如本链接所述。 对我来说主要的麻烦是我想在
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 6 年前。 Improve this ques
我通过将一个正方形旋转 45 度创建了一个菱形: .shape { height: 50px; width: 50px; transform: rotate(45deg); } 是否
我使用 css 创建了一个三 Angular 形: .box { width: 0; height: 0; border-style: solid; border-width: 540px 964px
如何创建边框三 Angular 形? 我唯一能想到的就是做一个三 Angular 形 .triangle { width: 0; height: 0;
我想创建一个旋转函数,在该函数中我的三 Angular 形可以像轮子一样自行旋转,但我与移动三 Angular 形的部分代码发生冲突,我尝试了许多解决方案但没有成功,也许如果你们中的一个人知道它会对人
我正在使用线性垫步进器。 它与 next 一起工作正常。我进行 api 调用,如果成功,则调用 stepper-next 事件而不是使用 matStepperNext 指令。 现在,当用户在第 1 步
我想根据用户的 onClick 事件将 V 形从 down 更改为 up。我尝试过使用其他人的其他示例,但没有成功。 这是我的JSFiddle . 最佳答案 嗯,您的 JSFiddle 设置存在一些问
我想在鼠标单击的地方绘制一个 2D 三 Angular 形。已经制作了鼠标事件处理程序,并且可以看到鼠标单击的点。我在缓冲区对象中写入了三 Angular 形的顶点位置。它将是三 Angular 形大
有人可以告诉我我在 Javascript 中的帕斯卡三 Angular 形上做错了什么吗?我看到一个已经存在的使用递归的线程,但是,在没有逐字复制的情况下,在我看来,代码看起来太相似,无法破译我做错了
我必须为我的类(class)使用星号制作一个三 Angular 形和倒三 Angular 形。 我已经制作了上半部分,但是,我在制作上下颠倒的部分时遇到了很大的麻烦 for(var count=1;
我想获取围绕一个点的三 Angular 形的点,其中面指向指定法线的方向。我将使用 THREE.js 将它们添加到 BufferGeometry。 非常粗略的绘图: 这是我到目前为止的代码: //Th
我从编程开始。我正在使用 JavaScript。 为了练习,我打印了一个像这样的三 Angular 形: * ** *** **** ***** 但我想从右向左打印,如下所示: * **
我需要在 Joint JS 中创建一些以圆形源开头并以三 Angular 形结尾的链接,反之亦然,得到了这个,但它不起作用: var link1 = new joint.dia.Link({
这个问题已经有答案了: 奥 git _a (1 个回答) 已关闭 6 年前。 我做了一些安静的搜索,发现了很多将星星和其他形状输出到无数图案中的方法,但我还没有找到任何关于如何使用用户生成的短语来做到
我正在尝试仅使用递归打印出字母 V 的形状。我在这个网站上看到了一些与我的问题相关的代码,但大多数使用循环而不是递归。 这是我的代码: public class Pattern { pub
这个问题在这里已经有了答案: How to Make A Chevron Arrow Using CSS? (10 个答案) 关闭 7 年前。 我想给this triangle中间略有下降,我不想要
我的问题是关于使用 Javascript 对其边进行三 Angular 形评估。以下代码是非常初始的版本,即使它可以工作。我想知道它是否可以更简化,或者有其他方法可以达到相同的结果。 谢谢! let
function makeLine(length) { var line = ""; for (var i = 1; i <= length; i++) { for (var j =
我是一名优秀的程序员,十分优秀!