- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我如何在图像上应用这些 Gabor 滤波器小波?
close all;
clear all;
clc;
% Parameter Setting
R = 128;
C = 128;
Kmax = pi / 2;
f = sqrt( 2 );
Delt = 2 * pi;
Delt2 = Delt * Delt;
% Show the Gabor Wavelets
for v = 0 : 4
for u = 1 : 8
GW = GaborWavelet ( R, C, Kmax, f, u, v, Delt2 ); % Create the Gabor wavelets
figure( 2 );
subplot( 5, 8, v * 8 + u ),imshow ( real( GW ) ,[]); % Show the real part of Gabor wavelets
end
figure ( 3 );
subplot( 1, 5, v + 1 ),imshow ( abs( GW ),[]); % Show the magnitude of Gabor wavelets
end
function GW = GaborWavelet (R, C, Kmax, f, u, v, Delt2)
k = ( Kmax / ( f ^ v ) ) * exp( 1i * u * pi / 8 );% Wave Vector
kn2 = ( abs( k ) ) ^ 2;
GW = zeros ( R , C );
for m = -R/2 + 1 : R/2
for n = -C/2 + 1 : C/2
GW(m+R/2,n+C/2) = ( kn2 / Delt2 ) * exp( -0.5 * kn2 * ( m ^ 2 + n ^ 2 ) / Delt2) * ( exp( 1i * ( real( k ) * m + imag ( k ) * n ) ) - exp ( -0.5 * Delt2 ) );
end
end
编辑:这是我图片的尺寸
最佳答案
Gabor 滤波器的典型用途是计算多个方向中每个方向的滤波器响应,例如用于边缘检测。
您可以使用 Convolution Theorem 将过滤器与图像进行卷积,通过对图像和滤波器的傅里叶变换的逐元素乘积进行傅里叶逆变换。这是基本公式:
%# Our image needs to be 2D (grayscale)
if ndims(img) > 2;
img = rgb2gray(img);
end
%# It is also best if the image has double precision
img = im2double(img);
[m,n] = size(img);
[mf,nf] = size(GW);
GW = padarray(GW,[n-nf m-mf]/2);
GW = ifftshift(GW);
imgf = ifft2( fft2(img) .* GW );
通常,对于大小 > 20 的内核,FFT 卷积更胜一筹。有关详细信息,我推荐C 中的数值食谱,它对方法及其注意事项有很好的语言无关描述。
您的内核已经很大,但是使用 FFT 方法它们可以和图像一样大,因为无论如何它们都会被填充到那个大小。由于 FFT 的周期性,该方法执行循环卷积。这意味着滤镜将环绕图像边界,因此我们还必须填充图像本身以消除这种边缘效应。最后,由于我们想要对所有过滤器的总响应(至少在典型的实现中),我们需要依次将每个过滤器应用于图像,然后对响应求和。通常一个人只使用 3 到 6 个方向,但在多个尺度(不同的内核大小)上进行过滤也很常见,因此在这种情况下会使用更多的过滤器。
你可以用这样的代码完成整个事情:
img = im2double(rgb2gray(img)); %#
[m,n] = size(img); %# Store the original size.
%# It is best if the filter size is odd, so it has a discrete center.
R = 127; C = 127;
%# The minimum amount of padding is just "one side" of the filter.
%# We add 1 if the image size is odd.
%# This assumes the filter size is odd.
pR = (R-1)/2;
pC = (C-1)/2;
if rem(m,2) ~= 0; pR = pR + 1; end;
if rem(n,2) ~= 0; pC = pC + 1; end;
img = padarray(img,[pR pC],'pre'); %# Pad image to handle circular convolution.
GW = {}; %# First, construct the filter bank.
for v = 0 : 4
for u = 1 : 8
GW = [GW {GaborWavelet(R, C, Kmax, f, u, v, Delt2)}];
end
end
%# Pad all the filters to size of padded image.
%# We made sure padsize will only be even, so we can divide by 2.
padsize = size(img) - [R C];
GW = cellfun( ...
@(x) padarray(x,padsize/2), ...
GW, ...
'UniformOutput',false);
imgFFT = fft2(img); %# Pre-calculate image FFT.
for i=1:length(GW)
filter = fft2( ifftshift( GW{i} ) ); %# See Numerical Recipes.
imgfilt{i} = ifft2( imgFFT .* filter ); %# Apply Convolution Theorem.
end
%# Sum the responses to each filter. Do it in the above loop to save some space.
imgS = zeros(m,n);
for i=1:length(imgfilt)
imgS = imgS + imgfilt{i}(pR+1:end,pC+1:end); %# Just use the valid part.
end
%# Look at the result.
imagesc(abs(imgS));
请记住,这基本上是最低限度的实现。您可以选择用边界的复制品而不是零来填充,对图像应用窗口函数或使填充尺寸更大以获得频率分辨率。这些中的每一个都是对我上面概述的技术的标准增强,通过 Google 进行研究应该是微不足道的。和 Wikipedia .另请注意,我没有添加任何基本的 MATLAB 优化,例如预分配等。
最后一点,如果您的过滤器总是比图像小得多,您可能希望跳过图像填充(即使用第一个代码示例)。这是因为,向图像添加零会在填充开始的地方创建一个人工边缘特征。如果过滤器很小,循环卷积的环绕不会导致问题,因为只有过滤器填充中的零会涉及。但是一旦滤波器足够大,环绕效应就会变得严重。如果必须使用大过滤器,则可能必须使用更复杂的填充方案,或裁剪图像的边缘。
关于image - 如何将 Gabor 小波应用于图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9003147/
我正在尝试学习 Knockout 并尝试创建一个照片 uploader 。我已成功将一些图像存储在数组中。现在我想回帖。在我的 knockout 码(Javascript)中,我这样做: 我在 Jav
我正在使用 php 编写脚本。我的典型问题是如何在 mysql 中添加一个有很多替代文本和图像的问题。想象一下有机化学中具有苯结构的描述。 最有效的方法是什么?据我所知,如果我有一个图像,我可以在数据
我在两个图像之间有一个按钮,我想将按钮居中到图像高度。有人可以帮帮我吗? Entrar
下面的代码示例可以在这里查看 - http://dev.touch-akl.com/celebtrations/ 我一直在尝试做的是在 Canvas 上绘制 2 个图像(发光,然后耀斑。这些图像的链接
请检查此https://jsfiddle.net/rhbwpn19/4/ 图像预览对于第一篇帖子工作正常,但对于其他帖子则不然。 我应该在这里改变什么? function readURL(input)
我对 Canvas 有疑问。我可以用单个图像绘制 Canvas ,但我不能用单独的图像绘制每个 Canvas 。- 如果数据只有一个图像,它工作正常,但数据有多个图像,它不工作你能帮帮我吗? va
我的问题很简单。如何获取 UIImage 的扩展类型?我只能将图像作为 UIImage 而不是它的名称。图像可以是静态的,也可以从手机图库甚至文件路径中获取。如果有人可以为此提供一点帮助,将不胜感激。
我有一个包含 67 个独立路径的 SVG 图像。 是否有任何库/教程可以为每个路径创建单独的光栅图像(例如 PNG),并可能根据路径 ID 命名它们? 最佳答案 谢谢大家。我最终使用了两个答案的组合。
我想将鼠标悬停在一张图片(音乐专辑)上,然后播放一张唱片,所以我希望它向右移动并旋转一点,当它悬停时我希望它恢复正常动画片。它已经可以向右移动,但我无法让它随之旋转。我喜欢让它尽可能简单,因为我不是编
Retina iOS 设备不显示@2X 图像,它显示 1X 图像。 我正在使用 Xcode 4.2.1 Build 4D502,该应用程序的目标是 iOS 5。 我创建了一个测试应用(主/细节)并添加
我正在尝试从头开始以 Angular 实现图像 slider ,并尝试复制 w3school基于图像 slider 。 下面我尝试用 Angular 实现,谁能指导我如何使用 Angular 实现?
我正在尝试获取图像的图像数据,其中 w= 图像宽度,h = 图像高度 for (int i = x; i imageData[pos]>0) //Taking data (here is the pr
我的网页最初通过在 javascript 中动态创建图像填充了大约 1000 个缩略图。由于权限问题,我迁移到 suPHP。现在不用标准 标签本身 我正在通过这个 php 脚本进行检索 $file
我正在尝试将 python opencv 图像转换为 QPixmap。 我按照指示显示Page Link我的代码附在下面 img = cv2.imread('test.png')[:,:,::1]/2
我试图在这个 Repository 中找出语义分割数据集的 NYU-v2 . 我很难理解图像标签是如何存储的。 例如,给定以下图像: 对应的标签图片为: 现在,如果我在 OpenCV 中打开标签图像,
import java.util.Random; class svg{ public static void main(String[] args){ String f="\"
我有一张 8x8 的图片。 (位图 - 可以更改) 我想做的是能够绘制一个形状,给定一个 Path 和 Paint 对象到我的 SurfaceView 上。 目前我所能做的就是用纯色填充形状。我怎样才
要在页面上显示图像,你需要使用源属性(src)。src 指 source 。源属性的值是图像的 URL 地址。 定义图像的语法是: 在浏览器无法载入图像时,替换文本属性告诉读者她们失去的信息。此
**MMEditing是基于PyTorch的图像&视频编辑开源工具箱,支持图像和视频超分辨率(super-resolution)、图像修复(inpainting)、图像抠图(matting)、
我正在尝试通过资源文件将图像插入到我的程序中,如下所示: green.png other files 当我尝试使用 QImage 或 QPixm
我是一名优秀的程序员,十分优秀!