あなたがしようとしていることを実装しようとしましたが、ありがたいことに、MATLABフォーラムから直接コードを取得しました。下の画像を見るとかなり良い結果を得ているようです。
私はあなたが欠けているものは画像を適切にグレースケールしていると思います。カラー画像にハイパスフィルタを直接適用し、グレースケール画像を期待していると思います。
また、実装したコードを共有して、最後に試してみることもできます。
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);
私は役立つことを望みます。助けがあれば、アップヴォートするか、答えとして受け入れることを忘れないでください。
答えをありがとう。私はこのMATLABコードを理解しています。私は自分のコードでそれをやろうとします。 C#またはjavaのコードを追加すると、私はあなたに感謝します。 –
私はあなたのコードは、ハイパスフィルタに渡す前に画像をグレースケールで完全に細かいと思う。 – Mayank