Reputation: 15
I know how to add noise to the image using the 'imnoise' function, but I was not getting how to add noise patch only to a part of the image, leaving the rest of the image untouched.
Could you please help?
Upvotes: 0
Views: 566
Reputation: 18895
You can add noise "in-place" without assigning an addition variable, for example like that:
% Test image.
img = uint8(repmat([zeros(20), 255*ones(20); 255*ones(20) zeros(20)], 5, 5));
% Show test image before noise.
figure(1);
imshow(img);
% Add noise only to part of image.
img(20:60, 20:80) = imnoise(img(20:60, 20:80), 'gaussian');
% Show test image after noise.
figure(2);
imshow(img);
Upvotes: 1
Reputation: 192
Probably the easiest way is to take a region of the original image (eg, region = img(4:40,50:60) add noise to that (call it region_with_noise) and then splice that back in (img(4:40,50:60) = region_with_noise). If you have an RGB image, you would have to repeat the process for each channel.
Upvotes: 0