- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试对彩色图像应用 FFT。我提取了三个分量:红色、绿色和蓝色,然后将 fft2
分别应用于每个分量,然后在每个平面中应用高斯滤波器。现在我试图在模糊后显示红色、绿色和蓝色分量。之后,我应用 ifft2
来获得结果。
我的问题是我在每个组件中看到一个灰色图像。我试图只显示颜色平面,但我的代码不起作用。此外,我想将这三个组件组合在一起以返回全彩色图像。我在下面写了以下代码。谁能告诉我我做错了什么?
% Calculate FFT for R , G , B images
I = imread ('lena.jpg');
% Extract three images
Red = I (: , : , 1);
Green = I (: , : , 2);
Blue = I(: , : , 3);
f_r = fftshift (Red);
F_r = fft2 (f_r);
f_g = fftshift (Green);
F_g = fft2 (f_g);
f_b = fftshift (Blue);
F_b = fft2 (f_b);
% Calculate the gaussian filter then find its FFT
h = fspecial( 'gaussian', [512 512] , 3.0 );
h = fftshift (h);
H = fft2(h); % Fourier Transform of 2D Gaussian
FF_R = H .* F_r ;
FF_G = H .* F_g;
FF_B = H .* F_b;
% This is to get red, green and blue images
b = zeros(512, 512);
% Inverse IFFT _RED
Ir = ifftshift(FF_R);
Irr= ifft2 (Ir);
I_R = fftshift (Irr);
IFF_R = 1 + log (abs(I_R));
figure , imshow (IFF_R , [ ]);
Con1 = im2uint8(IFF_R);
just_red_2 = cat(3, Con1, b, b);
figure, imshow (just_red_2);
% Inverse IFFT _Green
Ig = ifftshift(FF_G);
Igg= ifft2 (Ig);
I_G = fftshift (Igg);
figure , imshow (1+ log(abs(I_G)), [ ]);
just_green_2 = cat(3, b, I_G, b);
%figure, imshow (1 + log(abs(just_green_2)) );
% Inverse IFFT Blue
Ib = ifftshift(FF_B);
Ibb= ifft2 (Ib);
I_B = fftshift (Ibb);
figure , imshow (1+ log(abs(I_B)), [ ]);
just_blue_2 = cat(3, b,b, I_B);
%figure, imshow (1 + log(abs(just_blue_2)) );
%Combine the three component togather
%full_image2 = cat (3, FF_R , FF_G , FF_B);
full_image2 = cat (3, just_red_2 (:,:,1) , just_green_2(:,:,2) , just_blue_2(:, :, 3));
%full_image2 (: , : , 1) = FF_R (: , : , 1);
%full_image2 (: , : , 2) = FF_G (: , : , 2);
%full_image2 (: , : , 3) = FF_B (: , : , 3);
Full = ifft2 ( ifftshift(full_image2));
figure, imshow (Full , [ ])
Final = fftshift(Full);
figure , imshow ( full_image2 )
最佳答案
您正在进行大量不必要的计算。单独过滤平面后,您可以立即将它们组合起来。此外,您的红色组件正在执行 log
转换,而其他颜色 channel 没有执行此操作。此外,您实际上需要在转换图像后执行 fftshift
,以便您可以将光谱居中。您首先执行了 fftshift
,这是不正确的。同样的事情需要应用于您的过滤器定义。过滤图像后,您必须小心地反转操作。正向转换包括执行 fft2
,然后执行 fftshift
。反向操作要求您先 ifftshift
,然后是 ifft2
。您的操作方向相反。
我需要强调的一件事是,您需要将图像平面转换到两倍以保持计算精度不变。您不需要这样做,因此所有计算都在 uint8
中完成。
还需要注意的是,执行 ifft2
后可能会有一些剩余的虚部值,因此最好使用 real
来消除虚部。根据您的意见,我制作了一个图形,显示红色、绿色和蓝色组件,它们的色调完好无损,以及 2 x 2 Pane 中的最终模糊图像。
有了这个,这里是您的代码修改以适应我的意见。你也没有在你的帖子中包含你的图片,但我在维基百科上使用了 Lena 的一个版本:
现在,请记住我删除了您的许多代码以实现您的目标:
% Calculate FFT for R , G , B images
I = imread ('https://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png');
I = double(I); %// Change - cast to double
% Extract three images
Red = I (: , : , 1);
Green = I (: , : , 2);
Blue = I(: , : , 3);
% // Change - Transform, then shift
f_r = fft2(Red);
F_r = fftshift(f_r);
f_g = fft2(Green);
F_g = fftshift(f_g);
f_b = fft2(Blue);
F_b = fftshift(f_b);
% Calculate the gaussian filter then find its FFT
h = fspecial( 'gaussian', [512 512] , 3.0 );
%// Change - Filter, then FFT shift
H = fft2(h); % Fourier Transform of 2D Gaussian
H = fftshift(H);
% // Now filter
FF_R = H .* F_r ;
FF_G = H .* F_g;
FF_B = H .* F_b;
%// Change - perform ifftshift, then ifft2, then cast to real
% Inverse IFFT _RED
Ir = ifftshift(FF_R);
Irr = fftshift(real(ifft2(Ir)));
% Inverse IFFT _Green
Ig = ifftshift(FF_G);
Igg = fftshift(real(ifft2(Ig)));
% Inverse IFFT _Blue
Ib = ifftshift(FF_B);
Ibb = fftshift(real(ifft2(Ib)));
%// Visualize the red, green and blue components
b = zeros(512, 512, 'uint8');
image_red = cat(3,Irr, b, b);
image_green = cat(3, b, Igg, b);
image_blue = cat(3, b, b, Ibb);
%Combine the three component together
%// Change - Removed fluff
b = uint8(cat(3, Irr, Igg, Ibb));
%// NEW - Display each component as well as the final image in a new figure
figure;
subplot(2,2,1);
imshow(image_red);
subplot(2,2,2);
imshow(image_green);
subplot(2,2,3);
imshow(image_blue);
subplot(2,2,4);
imshow(b);
这是我得到的数字:
关于matlab - 使用 FFT 和 IFFT 对彩色图像进行低通滤波,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26744673/
我正在尝试学习 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
我是一名优秀的程序员,十分优秀!