Problem with filtering an image

4 vues (au cours des 30 derniers jours)
Rama Ratna
Rama Ratna le 20 Oct 2011
Commenté : Pallavi Bidri le 19 Fév 2019
Whats up folks I'm having a little problem in filtering this image: http://img15.imageshack.us/img15/9287/palhaco.png
The source code is bellow:
C = imread('Palhaco.png');
imshow(C);
figure;
g = fspecial('gaussian',15,2);
imagesc(g); colormap(gray);
surfl(g)
figure;
gC = convn(C,g,'same');
imshow(convn(C,[-1 1],'same'));
figure;
imshow(convn(gC,[-1 1],'same'));
figure;
dx = convn(g,[-1 1],'same');
imshow(convn(C,dx,'same'));
figure;
lg = fspecial('log',15,2);
lC = convn(C,lg,'same');
imshow(lC)
figure
imshow(C + .2*lC)
When I compile the program, It returns: "Integers can only be combined with integers of the same class, or scalar doubles."
I'm open to any idea at all!
  1 commentaire
Pallavi Bidri
Pallavi Bidri le 19 Fév 2019
By using imtool function, check the class of both images that you want to combine.
If any image is of different class, convert it to any1 class to match with the other by using the command,
im2double(image) %converts given image to class double
im2uint8(image) % converts the given image to class uint8
generally, im2---(image) % dash after im2 can be the desired class that you want to be of

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 21 Oct 2011
The code is very experimental so far. It seems like you're doing some experiments in trying to get rid of the pattern noise, but not doing a very good job of it (so far). Anyway, this will "fix" your code. It will at least run now without errors, and it does what you are telling it to do, even though that is kind of gibberish. As a bonus I put them all on one screen with titles above the images.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;
% Read in original color image.
folder = 'C:\Documents and Settings\myUserName\My Documents\Downloads';
baseFileName = 'Palhaco.png';
fullFileName = fullfile(folder, baseFileName);
rgbImage = imread(fullFileName);
subplot(3, 3, 1);
imshow(rgbImage);
title('Original Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Get a convolution kernel.
g = fspecial('gaussian',15,2);
subplot(3, 3, 2);
imshow(g, []);
title('g - Gaussian Kernel', 'FontSize', fontSize);
subplot(3, 3, 3);
surfl(g)
title('g - Gaussian Kernel', 'FontSize', fontSize);
grayImage = rgbImage(:,:,2); % Get green channel.
gC = conv2(grayImage, g,'same');
subplot(3, 3, 4);
imshow(conv2(grayImage,[-1 1],'same'));
title('gC - Original Image Convolved with g', 'FontSize', fontSize);
subplot(3, 3, 5);
imshow(conv2(grayImage,[-1 1],'same'));
title('Original Image Convolved with [-1 1]', 'FontSize', fontSize);
subplot(3, 3, 6);
imshow(conv2(gC,[-1 1],'same'));
title('gC convolved with [-1 1]', 'FontSize', fontSize);
dx = conv2(g,[-1 1],'same');
subplot(3, 3, 7);
imshow(convn(grayImage, dx, 'same'));
title('dx', 'FontSize', fontSize);
lg = fspecial('log',15,2);
lC = conv2(grayImage, lg, 'same');
subplot(3, 3, 8);
imshow(lC)
title('lC', 'FontSize', fontSize);
subplot(3, 3, 9);
imshow(single(grayImage) + .2*lC);
title('single(grayImage) + .2*lC', 'FontSize', fontSize);
  3 commentaires
Image Analyst
Image Analyst le 21 Oct 2011
I don't have time now. But the problem now is in your algorithm, not the MATLAB code, which I fixed. Do some research and try some things. Perhaps I'll get to it later.
Rama Ratna
Rama Ratna le 21 Oct 2011
Ok! I appreciate your attention, Thanks very much.

Connectez-vous pour commenter.

Plus de réponses (2)

Rama Ratna
Rama Ratna le 21 Oct 2011
On the other hand, I tried to pass a low-pass filter, but the results were not so good. Take a look:
sigma = 7;
h=fspecial('gaussian',[15, 15], sigma);
smoothedImage = imfilter(Image, h, 'same', 'conv');
The image obtained is kind of "clean" but blurred, is there any way to improve that?
Thx a lot

Rama Ratna
Rama Ratna le 21 Oct 2011
I've already done it. Thanks for ur attention.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by