how is imwrite() in Matlab2020a saving RGB?
Show older comments
I tried to add noise to one of the three color channels, say GREEN, save the new noisy image with imwrite(), open it again with imread(), and compare against the original. The image Ia has noise only on GREEn channel. Why is the noise in image Ib over all color channels after using imwrite() and reading the noisy image with imread()?
Here is the code:
=======
clear all;
close all;
clc;
I=imread('strawberries.jpg');
greenChannel=I(:,:,2);
%add noise to green channel
Ia=I;
Ia(:,:,2)=imnoise(greenChannel,'salt & pepper',0.01);
%save noisy image
imwrite(Ia,'./strawberries_noise1.jpg');
%read noisy image
Ib=imread('./strawberries_noise1.jpg');
%compare original and noisy image before imwrite()
I1a=double(I(:,:,1))-double(Ia(:,:,1));
I2a=double(I(:,:,2))-double(Ia(:,:,2));
I3a=double(I(:,:,3))-double(Ia(:,:,3));
%compare original and noisy image after imwrite()
I1b=double(I(:,:,1))-double(Ib(:,:,1));
I2b=double(I(:,:,2))-double(Ib(:,:,2));
I3b=double(I(:,:,3))-double(Ib(:,:,3));
figure;
subplot(2,3,1);imshow(mat2gray(I1a));title('no noise on RED')
subplot(2,3,2);imshow(mat2gray(I2a));title('noise on GREEN')
subplot(2,3,3);imshow(mat2gray(I3a));title('no noise on BLUE')
subplot(2,3,4);imshow(mat2gray(I1b));
subplot(2,3,5);imshow(mat2gray(I2b));
subplot(2,3,6);imshow(mat2gray(I3b));
Accepted Answer
More Answers (0)
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!