Problem with filtering an image
4 views (last 30 days)
Show older comments
Rama Ratna
on 20 Oct 2011
Commented: Pallavi Bidri
on 19 Feb 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 Comment
Pallavi Bidri
on 19 Feb 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
Accepted Answer
Image Analyst
on 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 Comments
Image Analyst
on 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.
More Answers (2)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!