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

查看:97
本文介绍了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 s数组,例如:

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>

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

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

现在,我知道我不应该过早地进行优化,并且我可能根本不会遇到这个问题,但是请记住,这仅仅是背景情况,并且在某些情况下,这实际上是最好的解决方案,无论是否这是解决 my 问题的最佳解决方案.

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不支持哈希表. 编辑,直到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天全站免登陆