Using a complex steerable filter on an image
Ältere Kommentare anzeigen
I'm trying to use a complex steerable filter on an image to give me different phase-images for a project. The whole process is documented in Pintea, et al "Hand tremor frequency estimation in videos". To do this I used the first derivative of the Gaussian and took the hilbert transform of it to give me a complex filter. However, after filtering it and trying to reconstruct it, I only get a blank gray image. I've tried just filtering the image with the first derivative of the Gaussian and it works. However, taking the hilbert transform of the Gaussian first derivative doesn't. I tried to get the phase of the complex filter and reconstrucintg using ifft2(). I've also tried to normalize the values from 0 to 255 after reconstructing using mat2gray(), which didn't help either. My code is shown below. Any help would be much appreciated!
% Define orientations and scales
orientations = [0, pi/4, pi/2, 3*pi/4]; % angles in radians
sigma = [1 0.5 0.25]; % standard deviation of Gaussian/scales
filter_size = 2*ceil(2*sigma)+1; % filter size
% Load input image
input_image = imread('surfing.jpg');
targetSize = [300 600];
r = centerCropWindow2d(size(input_image),targetSize);
input_image = imcrop(input_image,r);
input_image = rgb2gray(input_image);
% Perform cropping or select the region for the hand image
region = input_image;
% Initialize complex steerable pyramid
complex_pyramid = cell(length(orientations) * length(sigma), 1);
index = 1;
for i = 1:length(orientations)
for j = 1:length(sigma)
% Create complex steerable filters G and H for each orientation and scale
% Create a Gaussian filter
G = fspecial('gaussian', [filter_size(j), filter_size(j)], sigma(j));
% Compute the gradient of the Gaussian filter
[Gx, Gy] = gradient(G);
G1 = cos(orientations(i)) * Gx + sin(orientations(i)) * Gy; % Combine gradients based on orientation
rotated_filter = imrotate(G1, -orientations(i)*180/pi, 'loose'); % Negative angle for correct orientation
% Hilbert transform of Gaussian
h = hilbert(rotated_filter);
complex_filt{i+j-1} = h;
end
end
% testing complex gaussian steerability
filtered_images = cell(1, numel(orientations));
for i = 1:numel(orientations)
for j = 1:length(sigma)
conv_image = conv2(complex_filt{i},input_image);
% get phase only to normalize image
conv_image = double(conv_image);
phase = angle(conv_image);
complex_phase = exp(1j*phase);
% reconstruct image
reconstruct = ifft2(complex_phase);
filtered_images{i+j-1} = reconstruct
filtered_images{i+j-1} = conv_image;
end
end
figure;
imagesc(input_image); colormap gray;
% visualize
for i = 1:numel(orientations)
for j = 1:length(sigma)
figure;
imagesc(mat2gray(real(filtered_images{i}))*255); colormap gray;
title(['Orientation: ', num2str(orientations(i)), ', Scale: ', num2str(sigma(j))]);
% Display the imaginary and real parts of complex filters for debugging
figure;
subplot(1, 2, 1);
imagesc(real(complex_filt{i+j-1})); colormap gray;
title(['Real Part - Orientation: ', num2str(orientations(i)), ', Scale: ', num2str(sigma(j))]);
subplot(1, 2, 2);
imagesc(imag(complex_filt{i+j-1})); colormap gray;
title(['Imaginary Part - Orientation: ', num2str(orientations(i)), ', Scale: ', num2str(sigma(j))]);
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Image Category Classification finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!