📄 cmoviemaker.m
字号:
% load, display and return an image from the listfunction im = displayfile(nr, handles)im = imread(fullfile(handles.pathname, handles.filenames{nr}));if get(handles.checkbox_invert, 'Value'), im = max(im(:)) - im;endif isempty(handles.computeinfo.xlim), xvals = 1:size(im,2);else xvals = floor(handles.computeinfo.xlim(1):min(handles.computeinfo.xlim(2), size(im,2)));endif isempty(handles.computeinfo.ylim), yvals = 1:size(im,1);else yvals = floor(handles.computeinfo.ylim(1):min(handles.computeinfo.ylim(2),size(im,1)));endim = im(yvals, xvals);axes(handles.axes_top);imagesc([xvals(1) xvals(end)], [yvals(1) yvals(end)], im);axis equal tight; colormap gray; colorbar% displays the currently selected file in listbox_imagesfunction im = displaycurrentfile(handles)nr = get(handles.listbox_images, 'Value');im = displayfile(nr, handles);% 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}});% initialize level and dir listboxesfunction handles = initlistboxes(dims, handles)% dims dimensions of the current image% handles figure handlesim0 = zeros(dims);C0 = fdct_wrapping(im0,0);str = cell(1,length(C0));for ll=1:length(C0) str{ll} = sprintf('%d',ll);endset(handles.listbox_levels,'String',str)set(handles.listbox_levels,'Value',1:length(C0))str=cell(1,length(C0{2}));for dd=1:length(C0{2}) str{dd} = sprintf('%d',dd);endset(handles.listbox_dirs,'String',str)set(handles.listbox_dirs,'Value',1:length(C0{2}))handles.computeinfo.levels = 1:length(C0);for k=1:length(C0), handles.computeinfo.dirs{k} = 1:length(C0{k});endguidata(handles.listbox_levels, handles);% call to reinitialize listboxes for new image or new level selectionfunction handles = reinitlistboxes(nlev, handles)oldlevs = getlistboxvals(handles.listbox_levels);olddirs = getlistboxvals(handles.listbox_dirs);oldnrdirs = length(get(handles.listbox_dirs,'String'));firstclev = min(oldlevs(oldlevs > 1));% update levelsif nlev ~= length(get(handles.listbox_levels,'String')), str = cell(1, nlev); for ll=1:nlev, str{ll} = sprintf('%d',ll); end set(handles.listbox_levels,'String',str); if firstclev > nlev, % there were more levels in previous image, and only finer levels % selected => select finest level set(handles.listbox_levels,'Value',nlev); else set(handles.listbox_levels,'Value',oldlevs(oldlevs <= nlev)); endend% update dirsset(handles.listbox_dirs,'ListboxTop',1);if isempty(firstclev) || firstclev >= nlev, % only wavelet levels selected, only one dir str = {'1'}; nrdirs = 1; dirsel = 1;else nrdirs = 16 * 2.^(floor((firstclev-1)/2)); step = nrdirs/oldnrdirs; str = cell(1,nrdirs); dirsel = []; for dd=1:nrdirs, str{dd} = sprintf('%d',dd); if ismember(floor((dd-1)/step) + 1, olddirs), dirsel = [dirsel dd]; end endendset(handles.listbox_dirs,'String',str);set(handles.listbox_dirs,'Value',dirsel); % resizes the plotinfo structure and shows correct datafunction resizeplotinfo(nrows, ncols, handles)if ~isempty(nrows) && ~isempty(ncols), % update listbox_subplotidx str = cell(nrows, ncols); for kr = 1:nrows, for kc = 1:ncols, str{kr, kc} = sprintf('[%d,%d]', kr, kc); end end set(handles.listbox_subplotidx, 'String', {str{:}}); % resize plotinfo structure (saving old data), and layout member nel = nrows*ncols; sz = min(length(handles.plotinfo), nel); [ptypes{1:nel}] = deal(1); [ptypes{1:sz}] = deal(handles.plotinfo(1:sz).type); [ppos{1:nel}] = deal(1); [ppos{1:sz}] = deal(handles.plotinfo(1:sz).pos); [ptrans{1:nel}] = deal(1); [ptrans{1:sz}] = deal(handles.plotinfo(1:sz).transform); [pvals{1:nel}] = deal(1); [pvals{1:sz}] = deal(handles.plotinfo(1:sz).value); [pcbar{1:nel}] = deal(1); [pcbar{1:sz}] = deal(handles.plotinfo(1:sz).colorbar); handles.layout = [nrows ncols]; handles.plotinfo = struct('type',ptypes,'pos',ppos,'transform',ptrans,'value',pvals,'colorbar',pcbar); guidata(gcbo, handles)end% sets the threshold using a specified number of coefficients from the% first imagefunction handles = getthrshfromfirstimage(handles)im = imread(fullfile(handles.pathname, handles.filenames{1}));if get(handles.checkbox_invert, 'Value'), im = max(im(:)) - im;endif isempty(handles.computeinfo.xlim), xvals = 1:size(im,2);else xvals = floor(handles.computeinfo.xlim(1):min(handles.computeinfo.xlim(2), size(im,2)));endif isempty(handles.computeinfo.ylim), yvals = 1:size(im,1);else yvals = floor(handles.computeinfo.ylim(1):min(handles.computeinfo.ylim(2),size(im,1)));endim = im(yvals, xvals);ncoeff = str2double(get(handles.edit_thrshvalue, 'String'));if isnan(ncoeff) || isempty(ncoeff) || ncoeff <= 0, errordlg('Bad number of coefficients','Error in CMovieMaker!') returnendwtypes = {'db3','db5','dmey'};for k=unique(cat(2,handles.plotinfo.transform)), if k==1, C = fdct_wrapping(im, 0); [Cmod, thval{k}] = crvlt_keeplargest(C, round(ncoeff)); else nlev = max([1 (wmaxlev(size(im), wtypes{k-1}) - 1)]); % estimate number of useful levels [D, S] = wavedec2(im, nlev, wtypes{k-1}); Ds = sort(abs(D),2,'descend'); thval{k} = Ds(round(ncoeff)+1); endendhandles.computeinfo.thrshval = thval;handles.computeinfo.thrshtype = 2; % set type to thresholdingguidata(gcbo, handles);% --- Executes on button press in checkbox_invert.function checkbox_invert_Callback(hObject, eventdata, handles)% hObject handle to checkbox_invert (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)handles.computeinfo.invert = get(hObject, 'Value');guidata(hObject, handles);displaycurrentfile(handles);function edit_nrows_Callback(hObject, eventdata, handles)% hObject handle to edit_nrows (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)nrows = str2num(get(handles.edit_nrows, 'String'));ncols = str2num(get(handles.edit_ncols, 'String'));resizeplotinfo(nrows, ncols, handles);% --- Executes during object creation, after setting all properties.function edit_nrows_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_nrows (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit 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');endfunction edit_ncols_Callback(hObject, eventdata, handles)% hObject handle to edit_ncols (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)nrows = str2num(get(handles.edit_nrows, 'String'));ncols = str2num(get(handles.edit_ncols, 'String'));resizeplotinfo(nrows, ncols, handles);% --- Executes during object creation, after setting all properties.function edit_ncols_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_ncols (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit 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 selection change in listbox_subplotidx.function listbox_subplotidx_Callback(hObject, eventdata, handles)% hObject handle to listbox_subplotidx (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)curplot = get(hObject, 'Value');set(handles.popup_plottype, 'Value', handles.plotinfo(curplot).type);set(handles.popup_posplot, 'Value', handles.plotinfo(curplot).pos);set(handles.popup_transform, 'Value', handles.plotinfo(curplot).transform);set(handles.popup_values, 'Value', handles.plotinfo(curplot).value);set(handles.checkbox_colorbar, 'Value', handles.plotinfo(curplot).colorbar);% --- Executes during object creation, after setting all properties.function listbox_subplotidx_CreateFcn(hObject, eventdata, handles)% hObject handle to listbox_subplotidx (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: listbox 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 selection change in popup_posplot.function popup_posplot_Callback(hObject, eventdata, handles)% hObject handle to popup_posplot (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)curplot = get(handles.listbox_subplotidx, 'Value');handles.plotinfo(curplot).pos = get(hObject, 'Value');guidata(hObject, handles);% --- Executes during object creation, after setting all properties.function popup_posplot_CreateFcn(hObject, eventdata, handles)% hObject handle to popup_posplot (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_preview.function button_preview_Callback(hObject, eventdata, handles)% hObject handle to button_preview (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.hfig) || ~ishandle(handles.hfig), handles.hfig = figure; guidata(hObject, handles);endif get(handles.popup_thresh, 'Value') == 4, % get threshold from first image handles = getthrshfromfirstimage(handles);endnr = get(handles.listbox_images, 'Value');fullfilename = fullfile(handles.pathname, handles.filenames{nr});drawmovieframe(handles.hfig, fullfilename, handles.layout, handles.plotinfo, handles.computeinfo);% --- Executes on selection change in popup_transform.function popup_transform_Callback(hObject, eventdata, handles)% hObject handle to popup_transform (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)curplot = get(handles.listbox_subplotidx, 'Value');handles.plotinfo(curplot).transform = get(hObject, 'Value');guidata(hObject, handles);% --- Executes during object creation, after setting all properties.function popup_transform_CreateFcn(hObject, eventdata, handles)% hObject handle to popup_transform (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 selection change in popup_plottype.function popup_plottype_Callback(hObject, eventdata, handles)% hObject handle to popup_plottype (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)curplot = get(handles.listbox_subplotidx, 'Value');handles.plotinfo(curplot).type = get(hObject, 'Value');guidata(hObject, handles);% --- Executes during object creation, after setting all properties.function popup_plottype_CreateFcn(hObject, eventdata, handles)% hObject handle to popup_plottype (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 selection change in popup_values.function popup_values_Callback(hObject, eventdata, handles)% hObject handle to popup_values (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)curplot = get(handles.listbox_subplotidx, 'Value');handles.plotinfo(curplot).value = get(hObject, 'Value');guidata(hObject, handles);% --- Executes during object creation, after setting all properties.function popup_values_CreateFcn(hObject, eventdata, handles)% hObject handle to popup_values (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 checkbox_colorbar.function checkbox_colorbar_Callback(hObject, eventdata, handles)% hObject handle to checkbox_colorbar (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)curplot = get(handles.listbox_subplotidx, 'Value');handles.plotinfo(curplot).colorbar = get(hObject, 'Value');guidata(hObject, handles);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -