Hi all,
First of all, apologies in case this question has already been asked. I spent last week trying to find a solution on my own, and reading the documentation, but I can't.
I must say that the idea that I currently use works fine, but as I plan to include figures in my dissertation, I'd like them to look more 'professional'.
This is what this piece of code does:
- I load a grayscale image (in this case, a 2D mammography).
- I compute the gradients using a Sobel filter.
- In order to plot gradient vs pixel intensity (0-255), I reshape the original grayscale image and the gradient image (the magnitude image). Now each image has been reshaped as a 1xN vector, where N is the total number of pixels in the images.
- I create a scatter plot with both vectors.
im = imread('Images\2Dmammogram.jpg');
im_gray = rgb2gray(im);
im_gray = imresize(im_gray,0.25);
figure
imshow(im_gray)
title('Original image')
[mag,~] = imgradient(im_gray,'sobel');
ints = reshape(im_gray,1,[]);
magt = reshape(mag,1,[]);
figure
scatter(ints, magt,'w.')
set(gca,'color',[0 0 0])
title('Gradient of image w/o Gaussian noise')
With this code, the scatter plot seems 'fine':
However, I would like this to look smoother, and add some grayscale to the image, instead of only having 0s and 1s. I tried Kernel Density Esstimation (kdensity), but either I don't fully understand it or it doesnt really help in this situation:
X = [double(ints)', double(magt)'];
gridx1 = 0:1:255;
gridx2 = 0:2:ceil(max(magt))+1;
[x1, x2] = meshgrid(gridx1,gridx2);
x1 = x1(:);
x2 = x2(:);
xi = [x1(:) x2(:)];
disp('** Running Kernel Density Estimator **');
tic
figure
ksdensity(X,xi);
title('Bivariate mammography data')
toc
I will gladly accept any idea or recommendation. Am I doing KDE wrong?
Many thanks,
Ignacio