Image won`t output after noising.

I want to noise and then de-noise a "tire" image using 'salt & pepper', but I can't get a noised and de-noised image to output properly. The same happens with 'facets'.
load facets; nbc = size(map,1);
Y = imnoise(X,'salt & pepper',0.5);
colormap(gray(nbc));
subplot(221), image(wcodemat(X,nbc)); title('Original image');
subplot(222), image(wcodemat(Y,nbc)); title('Noised image');
load tire; nbc = size(map,1); wname = 'coif2'; lev = 3;
Y = imnoise(X,'salt & pepper',0.1);
[c,s] = wavedec2(Y,lev,wname);
det1 = detcoef2('compact',c,s,1);
sigma = median(abs(det1))/0.6745;
alpha = 5;
thr = wbmpen(c,3,sigma,alpha);
keepapp = 1;
xd = wdencmp('gbl',c,s,wname, lev,thr,'s',keepapp);
colormap(gray(nbc));
subplot(331), image(wcodemat(X,nbc)); title('Original image');
subplot(332), image(wcodemat(Y,nbc)); title('Noised image');
subplot(333), image(wcodemat(xd,nbc)); title('De-noised image');

4 Comments

Please include enough code and data that we can test it.
Try imagesc() instead of image()
Still nothing.
I've put all the code I used above.

Sign in to comment.

 Accepted Answer

load facets; nbc = size(map,1);
subplot(2,3,1); imshow(X,[]); title('as grayscale'); colorbar
Xcolor = ind2rgb(X, map);
Xgray = rgb2gray(Xcolor);
subplot(2,3,2); imshow(Xcolor); title('colored'); colorbar
subplot(2,3,3); imshow(Xgray,[]); title('color -> gray'); colorbar
Yraw_noise = imnoise(X,'salt & pepper',0.1);
Ygray_noise = imnoise(Xgray,'salt & pepper',0.1);
subplot(2,3,4); imshow(Yraw_noise,[]); title('as grayscale + noise'); colorbar
subplot(2,3,5); imshow(Ygray_noise,[]); title('gray + noise'); colorbar
This tells us that you have a pseudocolored image in which you have indices not grayscale levels, and that adding noise to the indices is not getting you the kind of results you want.

2 Comments

You're my saviour!
By the way, this is the fixed code for my initial question in case someone in the future will need it:
load tire; nbc = size(map,1); wname = 'coif2'; lev = 3;
Xcolor = ind2rgb(X, map);
X = rgb2gray(Xcolor);
Y = imnoise(X,'salt & pepper',0.1);
[c,s] = wavedec2(Y,lev,wname);
det1 = detcoef2('compact',c,s,1);
sigma = median(abs(det1))/0.6745;
alpha = 5;
thr = wbmpen(c,3,sigma,alpha);
keepapp = 1;
xd = wdencmp('gbl',c,s,wname,lev,thr,'s',keepapp);
subplot(331), imshow(X,[]); title('Original image');
subplot(332); imshow(Y,[]); title('Noised image');
subplot(333); imshow(xd,[]); title('De-noised image');

Sign in to comment.

More Answers (0)

Products

Release

R2023a

Tags

Asked:

on 12 Jun 2023

Edited:

on 12 Jun 2023

Community Treasure Hunt

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

Start Hunting!