A list,
Block matching is a common method in image denoising and motion estimation. By matching query blocks with adjacent image blocks, K blocks closest to query blocks are found from these adjacent blocks. The so-called adjacency is not absolute location adjacency, which can also lead to local search (local) and global search (non-local).
As shown above:
- Is a (red) centered window (search window), the largest gray matrix area;
- The matrix neighborhood is centered (an image block, query block), the purple matrix region;
- The matrix neighborhood is centered (an image block, a neighbor block), the purple matrix region.
If it represents the whole image, it is a global search, otherwise it is a local search.
1 pixel-based non-local Means In non-local Means image denoising, approximate blocks are used to estimate query blocks to achieve the purpose of denoising, as shown in the following formula: The weight calculation is as follows: Where is the smoothing parameter of the image, which is used to control the intensity of smoothing noise. If it is relatively small, the attenuation effect of the power function is relatively significant and the degree of detail retention is relatively high, so the detail information of the image itself will be maintained. In fact, not all neighboring blocks are similar to query blocks, so we can only consider several blocks with relatively large weights to estimate, that is, to sort the weights, and choose the significant blocks as similar blocks. This can not only improve the denoising effect but also reduce the amount of calculation. In addition, Mahmoudi’s article “Fast Non Local Means Denoising for 3D MR Images” also proposes a new method (selecting similar blocks based on the mean and variance of sums) to avoid many useless calculations (Euclidean distance). To avoid double counting, the mean and variance can be calculated in advance.
2. Non-local Means based on image blocks
The processing described in Part 2 is based on a single pixel (the center of each block), which results in a lot of computation. But what we actually calculate is the similarity of image blocks, so it can be extended to image block processing. As shown below:
Then the calculation of block matching becomes:
The weight estimation after optimization becomes:
An Optimized Blockwise NL-means Denoising Filter for 3D Magnetic Resonance Images is described as follows:
Among them:
- Nl-means, the original non-local means method
- Blockwise NL-means, refactoring one subblock at a time instead of a single pixel
- Optimized NL-means, Optimized the selection of weight of NL-means, and directly select several maximum weight
- Optimized Blockwise NL-means. The weight selection is Optimized for Optimized NL-means. It can be seen from above that the effect of treating a single pixel is better than that of treating a block each time, but the calculation time is longer. The effect is obviously improved after the weight parameters are optimized. In addition, the method of multi-threading is used in the optimized method.
Ii. Source code
function varargout = Gui_Main(varargin)
% GUI_MAIN MATLAB code for Gui_Main.fig
% GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing
% singleton*.
%
% H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to
% the existing singleton*.
%
% GUI_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_MAIN.M with the given input arguments.
%
% GUI_MAIN('Property'.'Value',...). creates anew GUI_MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Gui_Main_OpeningFcn gets called. An
% unrecognized property name orinvalid value makes property application % stop. All inputs are passed to Gui_Main_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Gui_Main
% Last Modified by GUIDE v2. 5 27-Apr- 2011. 09:29:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Gui_Main_OpeningFcn, ...
'gui_OutputFcn', @Gui_Main_OutputFcn, ...
'gui_LayoutFcn', [],...'gui_Callback'[]);if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Gui_Main is made visible.
function Gui_Main_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Gui_Main (see VARARGIN)
% Choose default command line output for Gui_Main
clc; warning off all;
axes(handles.axes1); cla reset; box on; set(gca, 'XTickLabel'[],'YTickLabel'[]); axes(handles.axes2); cla reset; box on;set(gca, 'XTickLabel'[],'YTickLabel'[]); axes(handles.axes3); cla reset; box on;set(gca, 'XTickLabel'[],'YTickLabel'[]); axes(handles.axes4); cla reset; box on;set(gca, 'XTickLabel'[],'YTickLabel'[]); handles.output = hObject; handles.file = []; handles.MStitch = []; handles.grayResult = []; handles.RGBResult = []; handles.grayListResult = []; handles.RGBListResult = []; %Update handles structure
guidata(hObject, handles);
% UIWAIT makes Gui_Main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Gui_Main_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output; % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --function uipushtool1_ClickedCallback(hObject, eventdata, handles)
% hObject handle to uipushtool1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uiputfile({'*.jpg; *.tif; *.png; *.gif'.'All Image Files'; .'*. *'.'All Files' }, 'Save results'.'Result\result_gui.jpg');
if isempty(filename)
return;
end
file = fullfile(pathname, filename);
f = getframe(gcf);
f = frame2im(f);
imwrite(f, file);
msgbox('Save GUI result image successful! '.'Prompt message'.'modal'); % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --function uipushtool2_ClickedCallback(hObject, eventdata, handles)
% hObject handle to uipushtool2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1); cla reset; box on; set(gca, 'XTickLabel'[],'YTickLabel'[]); axes(handles.axes2); cla reset; box on;set(gca, 'XTickLabel'[],'YTickLabel'[]); axes(handles.axes3); cla reset; box on;set(gca, 'XTickLabel'[],'YTickLabel'[]); axes(handles.axes4); cla reset; box on;set(gca, 'XTickLabel'[],'YTickLabel'[]); handles.file = []; handles.MStitch = []; handles.grayResult = []; handles.RGBResult = []; handles.grayListResult = []; handles.RGBListResult = []; [filename, pathname, filterindex] = uigetfile({'*.jpg; *.tif; *.png; *.gif; *.bmp'.'All Image Files'; .'*. *'.'All Files' }, 'Select image to process'.'.\\images\\'.'MultiSelect'.'on');
if ~isa(filename, 'cell') && isequal(filename, 0)
return;
end
file = File_Process(filename, pathname);
if length(file) < 2
msgbox('Please select at least two images! '.'Prompt message'.'modal');
return;
end
Img1 = imread(file{1});
Img2 = ImageList(file);
axes(handles.axes1);
imshow(Img1); title('Image Sequence 1'.'FontWeight'.'Bold');
axes(handles.axes2);
imshow(Img2); title('Image Sequence 2'.'FontWeight'.'Bold');
handles.Img1 = Img1;
handles.Img2 = Img2;
handles.file = file;
guidata(hObject, handles);
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1); cla reset; box on; set(gca, 'XTickLabel'[],'YTickLabel'[]); axes(handles.axes2); cla reset; box on;set(gca, 'XTickLabel'[],'YTickLabel'[]); axes(handles.axes3); cla reset; box on;set(gca, 'XTickLabel'[],'YTickLabel'[]); axes(handles.axes4); cla reset; box on;set(gca, 'XTickLabel'[],'YTickLabel'[]); handles.file = []; handles.MStitch = []; handles.grayResult = []; handles.RGBResult = []; dname = uigetdir('.\ images\ landscape images'.'Please select folder of images to be processed:');
if dname == 0
return;
end
df = ls(dname);
if length(df) > 2
for i = 1 : size(df, 1)
if strfind(df(i, :), '.db');
df(i, :) = [];
break;
end
end
if length(df) > 2
filename = fullfile(dname, df(end, :));
pathname = [dname '\]; else msgbox('Please select at least two images!', 'Prompt information', 'modal');
return;
end
else
msgbox('Please select at least two images! '.'Prompt message'.'modal');
return;
end
file = File_Process(filename, pathname);
if length(file) < 2
msgbox('Please select at least two images! '.'Prompt message'.'modal');
return;
end
Img1 = imread(file{1});
Img2 = ImageList(file);
axes(handles.axes1);
imshow(Img1); title('Image Sequence 1'.'FontWeight'.'Bold');
axes(handles.axes2);
imshow(Img2); title('Image Sequence 2'.'FontWeight'.'Bold');
handles.Img1 = Img1;
handles.Img2 = Img2;
handles.file = file;
guidata(hObject, handles);
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.
function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes2_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes3_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes4_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.file)
msgbox('Please load the image first! '.'Prompt message'.'modal');
return;
end
if isempty(handles.MStitch)
msgbox('Please match the image first! '.'Prompt message'.'modal');
return;
end
if ~isempty(handles.grayResult)
msgbox('Grayscale Mosaic image complete! '.'Prompt message'.'modal');
return;
end
if length(handles.file)
[MStitch, result] = GrayMain_Process(handles.MStitch, ...
handles.W_box, handles.H_box, handles.bdown);
end
Copy the code
3. Operation results
Fourth, note
Version: 2014 a