Removing noise of an image
2 views (last 30 days)
Show older comments
I want to remove noise using the following example
but I receive error message after:
I = imread('eight.tif');
>> figure
imshow(I)
Warning: Image is too big to fit on screen; displaying at 50%
> In images.internal.initSize (line 71)
In imshow (line 305)
>> J = imnoise(I,'salt & pepper',0.02);
figure
imshow(J)
Warning: Image is too big to fit on screen; displaying at 50%
> In images.internal.initSize (line 71)
In imshow (line 305)
>> Kaverage = filter2(fspecial('average',3),J)/255;
figure
imshow(Kaverage)
Undefined function 'conv2' for input arguments of type 'double' and attributes 'full 3d real'.
Error in filter2 (line 59)
y = conv2(hcol, hrow, x, shape);
What do I have to correct?
0 Comments
Answers (2)
Walter Roberson
on 12 Mar 2016
You cannot apply conv2() to all of an RGB image at once. You need to process it one channel at a time.
4 Comments
Image Analyst
on 12 Mar 2016
This code works perfectly fine:
I = imread('eight.tif');
imshow(I)
[rows, columns, numberOfColorChannels] = size(I)
J = imnoise(I,'salt & pepper',0.02);
figure
imshow(J)
Kaverage = filter2(fspecial('average',3),J)/255;
figure
imshow(Kaverage)
All I added was a call to size() to show how many color channels it is. It shows
rows =
242
columns =
308
numberOfColorChannels =
1
Note that numberOfColorChannels = 1 which means it's grayscale. Yours must be 3 which means it's color. Because your J, and therefore I, are color, this proves that somehow either
- you sometime prior overwrote your version of the standard demo image 'eight.tif' with a color version of it,
- or there is code in your script that you did not show us.
What I would do is to reinstall MATLAB to restore your original, proper demo images.
2 Comments
Image Analyst
on 12 Mar 2016
Again, reinstall. You should not want corrupted/changed versions of the standard demo images. As you've seen, it has already led to problems and will lead to problems again in the future if you don't restore them to their original version.
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!