A 3 x 3 mask is adopted.we have to decide whether a pixel is located in smooth region.if the result is negative,then it belongs to noisy-free.else the pixel is noisy.
MATLAB: How to check whether the noisy pixel is in a smooth region
decision tree based denoisingimage processingImage Processing Toolboxnoisy pixel
Related Solutions
Here's one way:
% Demo to extract and swap bitplanes in a gray scale image.
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');if button == 1 baseFileName = 'cameraman.tif';elseif button == 2 baseFileName = 'moon.tif';elseif button == 3 baseFileName = 'eight.tif';elseif button == 4 baseFileName = 'coins.png';else baseFileName = 'pout.tif';end% Read in a standard MATLAB gray scale demo image.folder = fullfile(matlabroot, '\toolbox\images\imdemos');% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);if ~exist(fullFileName, 'file') % Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName); uiwait(warndlg(errorMessage)); return; endendgrayImage = imread(fullFileName);% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);% Display the original gray scale image.
subplot(2, 1, 1);imshow(grayImage, []);title('Original Grayscale Image', 'FontSize', fontSize);% Get the 3rd bitplane
bitPlane3Image = bitget(grayImage, 3);% Get the 5th bitplane
bitPlane5Image = bitget(grayImage, 5);% Make the 3rd bitplane the 5th one.
grayImage = bitset(grayImage, 3, bitPlane5Image);% Make the 5th bitplane the 3rd one.
grayImage = bitset(grayImage, 5, bitPlane3Image);% Display the original gray scale image.subplot(2, 1, 2);imshow(grayImage, []);title('Modified Grayscale Image', 'FontSize', fontSize);fprintf('Done running %s.m.\n', mfilename);msgbox('Done with demo');
I see no reason why imquantize() won't work. Please show your code that demonstrates why imquantize() fails.
Alternatively you can use mat2gray followed by multiplication, as this demo shows:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;format compact;fontSize = 15;% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');if button == 1 baseFileName = 'cameraman.tif';elseif button == 2 baseFileName = 'moon.tif';elseif button == 3 baseFileName = 'eight.tif';elseif button == 4 baseFileName = 'coins.png';else baseFileName = 'pout.tif';end% Read in a standard MATLAB gray scale demo image.folder = fullfile(matlabroot, '\toolbox\images\imdemos');baseFileName = baseFileName;% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);% Check if file exists.
if ~exist(fullFileName, 'file') % File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName); uiwait(warndlg(errorMessage)); return; endendgrayImage = imread(fullFileName);% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);% Display the original gray scale image.
subplot(2, 2, 1);imshow(grayImage, []);title('Original Grayscale Image', 'FontSize', fontSize);% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off') % Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);subplot(2, 2, 2); bar(pixelCount);grid on;title('Histogram of original image', 'FontSize', fontSize);xlim([0 grayLevels(end)]); % Scale x axis manually.
% Quantize
numberOfGrayLevels = 4;quantizedImage = uint8(mat2gray(grayImage) * (numberOfGrayLevels-1));% Display the original gray scale image.subplot(2, 2, 3);imshow(quantizedImage, []);caption = sprintf('Image quantized into %d gray levels', numberOfGrayLevels);title(caption, 'FontSize', fontSize);% Enlarge figure to full screen.set(gcf, 'units','normalized','outerposition',[0 0 1 1]);% Give a name to the title bar.set(gcf,'name','Demo by ImageAnalyst','numbertitle','off') % Let's compute and display the histogram.[pixelCount grayLevels] = imhist(quantizedImage);subplot(2, 2, 4); bar(pixelCount);grid on;caption = sprintf('Histogram of image quantized into %d gray levels', numberOfGrayLevels);title(caption, 'FontSize', fontSize);lastGL = find(pixelCount>0, 1, 'last');xlim([0 lastGL+1]); % Scale x axis manually.
Best Answer