简体   繁体   English

在 UWP C# 中应用高通滤波器

[英]Applying high pass filter in UWP C#

I am trying to apply high pass filter in my UWP windows 10 app.我正在尝试在我的 UWP Windows 10 应用程序中应用高通滤波器。 First I am blurring the image.首先,我正在模糊图像。 Then I am subtracting blurred image from the original image.然后我从原始图像中减去模糊图像。 The result I have got is like我得到的结果就像

在此处输入图片说明

Where as I have seen different examples of high pass filtering online, the result should like this正如我在网上看到的高通滤波的不同例子,结果应该是这样的

在此处输入图片说明

I have done this using photoshop.我是用photoshop完成的。 I want to get this result after applying above algorithm, but getting blackish image.我想在应用上述算法后得到这个结果,但得到黑色图像。

I have followed this article to do it.我已经按照这篇文章去做了。

I tried to implement what you are trying to do, and thankfully i got a code directly from MATLAB forum, and seems like i am getting pretty good results as you can have a look in the image below.我试图实现你想要做的事情,谢天谢地,我直接从 MATLAB 论坛得到了一个代码,看起来我得到了很好的结果,你可以看看下图。 在此处输入图片说明

I think what you are missing here is gray-scaling the image properly.I think you are applying high pass filter directly to colored image and expecting a grayscaled image.我认为您在这里缺少的是正确灰度图像。我认为您将高通滤波器直接应用于彩色图像并期待灰度图像。

I will also share the code i implemented so that you can also give a try on your end.我还将分享我实现的代码,以便您也可以尝试一下。

clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
imtool close all;  % Close all imtool figures.
clear;  % Erase all existing variables.
workspace;  % Make sure the workspace panel is showing.
Image = imread('highPassFilter.jpg');   % Image from stack over flow

%converting image to grayscale
grayImage=rgb2gray(Image);

% Get the dimensions of the image.  numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize')); 
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off') 
% Filter 1
kernel1 = -1 * ones(3)/9;
kernel1(2,2) = 8/9
% Filter the image.  Need to cast to single so it can be floating point
% which allows the image to have negative values.
filteredImage = imfilter(single(grayImage), kernel1);
% Display the image.
subplot(2, 2, 2);
imshow(filteredImage, []);
title('Filtered Image', 'FontSize', fontSize);
% Filter 2
kernel2 = [-1 -2 -1; -2 12 -2; -1 -2 -1]/16;
% Filter the image.  Need to cast to single so it can be floating point
% which allows the image to have negative values.
filteredImage = imfilter(single(grayImage), kernel2);
% Display the image.
subplot(2, 2, 3);
imshow(filteredImage, []);
title('Filtered Image', 'FontSize', fontSize);

I hope that helps.我希望这有帮助。 Dont forget to upvote or accept as answer if it helps.如果有帮助,请不要忘记投票或接受作为答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM