📄 cviewer.m
字号:
function menu_plot_curveletpos_top_CreateFcn(hObject, eventdata, handles)% hObject handle to menu_plot_curveletpos_top (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end% --- Executes on button press in button_go.function button_go_Callback(hObject, eventdata, handles)% hObject handle to button_go (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)mbh = msgbox('Working...');if get(handles.radio_showimage,'Value') == get(handles.radio_showimage,'Max'), [nnzcf, nel] = crvlt_countnnz(handles.C); set(handles.text_nrcoeffs, 'String', sprintf('Contains %d coeffs.', nel)); cmax = getlargestcoeff(handles.C); set(handles.text_maxvalue, 'String', sprintf('Max coeff value: %.2g', cmax)); C0 = handles.C; levels = getlistboxvals(handles.listbox_levels); dirs = getlistboxvals(handles.listbox_dirs); totdirs = length(get(handles.listbox_dirs,'String')); for ll=1:length(C0) levok = ismember(ll,levels); ndir = length(C0{ll}); if ndir ==1, if ~levok, C0{ll}{1} = zeros(size(C0{ll}{1})); end else step = round(ndir/totdirs); for dd=1:ndir, dirok = ismember(floor((dd-1)/step) + 1, dirs); if ~(levok && dirok) C0{ll}{dd} = zeros(size(C0{ll}{dd})); end end end end handles.Cmod = threshold_coeffs(C0, handles); handles.rim = ifdct_wrapping(handles.Cmod, 0); handles.frim = fftshift(fft2(handles.rim)); handles.errim = handles.rim - handles.im; handles.ferrim = handles.frim - handles.fim; if strcmp(get(handles.showdirdata_tool, 'State'), 'on') && ~isempty(handles.curdirdata), % update directional data levels = getlistboxvals(handles.listbox_levels); levels = levels(levels > 1 & levels < length(get(handles.listbox_levels,'String'))); [dirs, vals] = crvlt_getdirdata(handles.C, handles.curdirdata.dotcoords, levels); handles.curdirdata.levels = levels; handles.curdirdata.dirs = dirs; handles.curdirdata.values = vals; end elseif get(handles.radio_showcurvelet,'Value') == get(handles.radio_showcurvelet,'Max'), im0 = zeros(handles.imdims); C0 = fdct_wrapping(im0,0); levels = getlistboxvals(handles.listbox_levels); dirs = getlistboxvals(handles.listbox_dirs); totdirs = length(get(handles.listbox_dirs,'String')); for ll=levels ndir = length(C0{ll}); if ndir ==1, cx = floor((size(C0{ll}{1},1)-1)/2) + 1; cy = floor((size(C0{ll}{1},2)-1)/2) + 1; C0{ll}{1}(cx,cy) = 1; else step = round(ndir/totdirs); for dd=(step*(dirs-1)+1), for dofs=0:step-1, didx = dd + dofs; cx = floor((size(C0{ll}{didx},1)-1)/2) + 1; cy = floor((size(C0{ll}{didx},2)-1)/2) + 1; C0{ll}{didx}(cx,cy) = 1; end end end end handles.C = C0; handles.Cmod = C0; handles.im = ifdct_wrapping(C0, 0); handles.fim = fftshift(fft2(handles.im)); handles.rim = handles.im; handles.frim = handles.fim; handles.errim = handles.rim - handles.im; handles.ferrim = handles.frim - handles.fim; endclose(mbh);guidata(hObject, handles);displaydata(handles)% --- Executes when selected object is changed in displaychoice_panel.function displaychoice_panel_SelectionChangeFcn(hObject, eventdata, handles)% hObject handle to the selected object in displaychoice_panel % eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)handles.stickyaxes = 0;if get(handles.radio_showcurvelet,'Value') == get(handles.radio_showcurvelet,'Max'), handles.im = zeros(handles.imdims); handles.C = fdct_wrapping(handles.im, 0); handles.fim = fftshift(fft2(handles.im)); handles = reinitlistboxes(handles); button_go_Callback(get(hObject,'Parent'), eventdata, handles);else handles.im = handles.loadedim; handles.C = fdct_wrapping(handles.im, 0); handles.fim = fftshift(fft2(handles.im)); handles = reinitlistboxes(handles); button_go_Callback(get(hObject,'Parent'), eventdata, handles);end%% --- Own helper functions --- %%% True if disptype is the index of a physical space display typefunction isphys = isphysspace(disptype)isphys = ismember(disptype, [1 3 5]);% Get selected values from a listbox containing values as entriesfunction vals = getlistboxvals(lbhandle)% lbhandle handle to a listboxsel = get(lbhandle,'Value');strs = get(lbhandle,'String');vals = str2double({strs{sel}});% Display the data stored in handlesfunction displaydata(handles)keeplims = handles.stickyaxes;showinaxis(handles.axes_top, get(handles.displaymenu_top,'Value'), ... get(handles.menu_plot_curveletpos_top,'Value'), get(handles.plottype_menu_top,'Value'), keeplims, handles);if strcmp(get(handles.showdirdata_tool, 'State'), 'on'), makedirplot(handles.axes_bottom, handles)elseif strcmp(get(handles.anisomeas_tool, 'State'), 'on'), makeanisoplot(handles.axes_bottom, handles)else showinaxis(handles.axes_bottom, get(handles.displaymenu_bottom,'Value'), 1, ... get(handles.plottype_menu_bottom,'Value'), keeplims, handles);endl2err = norm(handles.errim(:)/sqrt(numel(handles.errim)));set(handles.edit_l2error, 'String', sprintf('%.5g', l2err))psnr = 20 * log10((max(handles.im(:)) - min(handles.im(:))) / l2err);set(handles.edit_PSNR, 'String', sprintf('%.5f', psnr));% Display a type of data in an axisfunction showinaxis(ax, type, postype, valuetype, keeplims, handles)% ax handle to axis to plot in% type the plot types in displaymenu_top/bottom% postype the type of position plot, as in menu_plot_curveletpos_top/bottom% handles figure handlesphysspace = isphysspace(type);if ~physspace, % compute frequency axes fsize = size(handles.fim); fdim = 2*pi*[-floor(fsize(1)/2) floor((fsize(1)-1)/2) ... -floor(fsize(2)/2) floor((fsize(2)-1)/2)];endcurtag = get(ax, 'Tag'); % save to preserve tagaxes(ax)curlims = axis(ax);clahold offswitch type, case 1, imagesc(funcimag(handles.im, valuetype)); axis equal tight; colorbar title('Original image, physical space') case 2, imagesc(fdim(1:2),fdim(3:4),funcimag(handles.fim, valuetype)); axis equal tight; colorbar title('Original image, frequency space') case 3, imagesc(funcimag(handles.rim, valuetype)); axis equal tight; colorbar title('Reconstructed image, physical space') case 4, imagesc(fdim(1:2),fdim(3:4),funcimag(handles.frim, valuetype)); axis equal tight; colorbar title('Reconstructed image, frequency space') case 5, imagesc(funcimag(handles.errim, valuetype)); axis equal tight; colorbar title('Error, physical space') case 6, imagesc(fdim(1:2),fdim(3:4),funcimag(handles.ferrim, valuetype)); axis equal tight; colorbar title('Error, frequency space') case 7, levs = getlistboxvals(handles.listbox_levels); dirs = getlistboxvals(handles.listbox_dirs); if levs(1) == 1 || levs(1) == length(handles.C), dirs = 1; end imagesc(funcimag(handles.C{levs(1)}{dirs(1)}, valuetype)); axis square tight; colorbar title(sprintf('Coefficients (level %d, dir %d) - original', levs(1), dirs(1))) case 8, levs = getlistboxvals(handles.listbox_levels); dirs = getlistboxvals(handles.listbox_dirs); if levs(1) == 1 || levs(1) == length(handles.Cmod), dirs = 1; end imagesc(funcimag(handles.Cmod{levs(1)}{dirs(1)}, valuetype)); axis square tight; colorbar title(sprintf('Coefficients (level %d, dir %d) - reconstruction', levs(1), dirs(1)))endif physspace, switch postype, case 1, % do nothing case 2, % large dots plotcurveletpos(handles.Cmod, ax, 0, 6); case 3, % small dots plotcurveletpos(handles.Cmod, ax, 0, 1); case 4, % scaled arrows plotcurveletpos(handles.Cmod, ax, 1, 1); case 5, % non-scaled arrows plotcurveletpos(handles.Cmod, ax, 1, 0); endend% set colormapcmapstr = get(handles.popup_colormap,'String');map = colormap(cmapstr{get(handles.popup_colormap,'Value')});if get(handles.checkbox_invertcolormap,'Value') == 1, map = flipud(map); colormap(map);endzoom('reset') % set maximum zoom outif keeplims, % keep the previous limits axis(ax, curlims)end% set the callback function for clicking in image (set for all children to% axes)if physspace && isequal(ax, handles.axes_top), if ~isempty(handles.curdirdata) && strcmp(get(handles.showdirdata_tool,'State'), 'on'), hold(ax, 'on') crd = handles.curdirdata.dotcoords; handles.curdirdata.dothandle = plot(ax, crd(1), crd(2), 'r*'); end hc = get(ax, 'Children'); set(hc, 'ButtonDownFcn', 'cviewer(''axis_clickcallback'',gcbo,[],guidata(gcbo))');endset(ax, 'Tag', curtag) % reset the axes tag (destroyed by plotting)handles.stickyaxes = 1; % make the axes remain the same next time we plotguidata(gcbo, handles);% apply function, do averages and sum for directional datafunction [levs, dirs, vals] = preparedirdata(dirdata, valuetype, avgsize, sum)levs = dirdata.levels; dirs = dirdata.dirs; vals = dirdata.values;nlevs = length(levs);% apply functionfor k=1:nlevs, vals{k} = funcimag(vals{k},valuetype);end% sum over levelsif sum, maxdirs = max(cat(2,dirdata.dirs{:})); data = zeros(1,maxdirs); for k=1:nlevs, step = round(maxdirs/length(dirs{k})); data = data + reshape(repmat(vals{k},[step 1]),[1 maxdirs]); end levs = 1; nlevs = 1; vals = {data}; dirs = {1:maxdirs};endif avgsize > 1 % compute sliding average for k=1:nlevs, lshift = -floor(avgsize/2); rshift = avgsize + lshift - 1; avgdata = zeros(size(vals{k})); for sh = lshift:rshift, avgdata = avgdata + circshift(vals{k}, [0 sh]); end vals{k} = avgdata / avgsize; endend% plots the coefficient values for all dirs on specified levelsfunction plotdirections(ax, dirdata, valuetype, plottype, avgsize, sum)% ax axes to plot in% dirdata levels, dirs, values for directional data - see% handles.curdirdata% valuetype type of value to plot, see funcimag() and plottype_menu_top% plottype 0 for rectangular, 1 for polarcolors = {'b*-', 'r*-', 'c*-', 'g*-', 'm*-'}; curtag = get(ax,'Tag');axes(ax)clahold off
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -