MATLAB 中的哈希表 [英] Hash tables in MATLAB

查看:61
本文介绍了MATLAB 中的哈希表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MATLAB 是否支持哈希表?

Does MATLAB have any support for hash tables?

我正在处理 Matlab 中的一个问题,该问题需要图像的尺度空间表示.为此,我在某个范围内为 k 创建了一个方差 sigma*s^k 的二维高斯滤波器,然后我依次使用每个滤波器来过滤图片.现在,我想要某种从 k 到过滤图像的映射.

I am working on a problem in Matlab that requires a scale-space representation of an image. To do this I create a 2-D Gaussian filter with variance sigma*s^k for k in some range., and then I use each one in turn to filter the image. Now, I want some sort of mapping from k to the filtered image.

如果 k 总是一个整数,我会简单地创建一个 3D 数组,这样:

If k were always an integer, I'd simply create a 3D array such that:

arr[k] = <image filtered with k-th guassian>

但是,k 不一定是整数,所以我不能这样做.我想做的是保持一个 k 的数组,这样:

However, k is not necessarily an integer, so I can't do this. What I thought of doing was keeping an array of ks such that:

arr[find(array_of_ks_ = k)] = <image filtered with k-th guassian>

乍一看似乎很不错,除了我可能会使用大约 20 或 30 个 k 值进行这种查找几千次,而且我担心这会影响性能.

Which seems pretty good at first thought, except I will be doing this lookup potentially a few thousand times with about 20 or 30 values of k, and I fear that this will hurt performance.

我想知道使用某种哈希表是否会更好地执行此操作,以便我的查找时间为 O(1) 而不是 O(n).

I wonder if I wouldn't be better served doing this with a hash table of some sort so that I would have a lookup time that is O(1) instead of O(n).

现在,我知道我不应该过早地进行优化,我可能根本没有这个问题,但请记住,这只是背景,可能有一些情况下这确实是最佳解决方案,无论是否这是我的问题的最佳解决方案.

Now, I know that I shouldn't optimize prematurely, and I may not have this problem at all, but remember, this is just the background, and there may be cases where this is really the best solution, regardless of whether it is the best solution for my problem.

推荐答案

Matlab 不支持哈希表.EDIT 直到 r2010a,即;参见 @Amro 的回答.

Matlab does not have support for hashtables. EDIT Until r2010a, that is; see @Amro's answer.

要加快查找速度,您可以删除 find,并使用 逻辑索引.

To speed up your look-ups, you can drop the find, and use LOGICAL INDEXING.

arr{array_of_ks==k} = <image filtered with k-th Gaussian>

arr(:,:,array_of_ks==k) = <image filtered with k-th Gaussian>

然而,在我使用 Matlab 的所有经验中,我从未发现查找成为瓶颈.

However, in all my experience with Matlab, I've never had a lookup be a bottleneck.

为了加快您的具体问题,我建议使用增量过滤

To speed up your specific problem, I suggest to either use incremental filtering

arr{i} = GaussFilter(arr{i-1},sigma*s^(array_of_ks(i)) - sigma*s^(array_of_ks(i-1)))

假设 array_of_ks 按升序排序,GaussFilter 根据方差计算滤波器掩码大小(当然还使用 2 个 1D 滤波器),或者您可以在傅立叶空间中进行过滤,即如果方差分布均匀(很可能不是很不幸),这对于大型图像特别有用.

assuming array_of_ks is sorted in ascending order, and GaussFilter calculates the filter mask size based on the variance (and uses, 2 1D filters, of course), or you can filter in Fourier Space, which is especially useful for large images and if the variances are spaced evenly (which they most likely aren't unfortunately).

这篇关于MATLAB 中的哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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