The image can not be displayed with imshow

advertisements

Input Image is

i was trying to apply hilbert transform on images. My aim is to detect the edges in the image. I cannot display the image. My code is as follows:

clear; close all;
I = imread('sub.png');
ty    = rgb2gray(I);
figure; imshow(ty)
ty= double(ty);
ty = adapthisteq(ty);
filtSize = 10;
H1 = fspecial('gaussian',[filtSize,filtSize],2);
H2 = fspecial('gaussian',[filtSize,filtSize],2);
H = H2-H1;
Hedge = imag(hilbert(H));
Iodd = sqrt(imfilter(ty,Hedge).^2 + imfilter(ty,Hedge.').^2);
figure; imshow(Iodd)
G = log(Iodd);
G = max(G(:)) - G;
figure,
imshow(G), colorbar

output is:

2) Is there any difference between the result of gradient of an image and hilbert transform?


It has absolutely nothing to do with the output.

In your code Iodd has all zero values. that means that log(Iodd) is undefined, thus NaN. G is just NaN.

And that is, unfortunately, because you have little idea of what you are doing!

First of all, adapthisteq needs a double image, but WAIT! an image whos data is of type double and a double image is not exactly the same. A double image is an image from 0-1 and an image whos data is double is just a memory thing. You want the 0-1. Therefore you dont want ty= double(ty);, you want ty= im2double(ty);. Check the difference of the two by adding a imshow(ty) just after adapthisteq.

And then your next part of the code. You do some fancy stuff! hilbert, imag, kernels, ... nice. Unfortunately , again, you are making a big mistake!

I suggest you have a closer look to this piece of code:

H1 = fspecial('gaussian',[filtSize,filtSize],2);
H2 = fspecial('gaussian',[filtSize,filtSize],2);
H = H2-H1;

If you look closely you will realize quite soon that you are creating 2 identical kernels and the subtracting them. Guess what H has as value.

You are filtering an image with a kernel that is all zeros. And then taking the logarithm!!!!