⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cviewer.m

📁 Edge detection in microscopy images using curvelets
💻 M
📖 第 1 页 / 共 4 页
字号:
% apply transformations to data (function, circular average, sum)[levs, dirs, vals] = preparedirdata(dirdata, valuetype, avgsize, sum);maxdirs = max(cat(2,dirs{:}));nlev = length(levs);if plottype    % sort levels according to max value to plot largest values first    % (important for polar plot)    maxval = zeros(1,nlev);    for k=1:nlev,        maxval(k) = max(funcimag(vals{k}(:), valuetype));    end    % sort both columns in descending order after first column    levorder = sortrows([maxval' (1:nlev)'], -1);else    levorder = repmat((1:nlev)',[1 2]);endlegstrs = cell(1,nlev);cnt = 1;for k=levorder(:,2)',    ndirs = length(dirs{k});    % plot (rectangular or polar)    if plottype == 0,        step = maxdirs / ndirs;        X = step*(0.5:ndirs-0.5) + 0.5;        plot(ax, X, vals{k}, colors{min(levs(k), length(colors))})    else        angles = crvlt_getangle(1:ndirs, ndirs);        polar(ax, [angles angles(1)], [vals{k} vals{k}(1)], colors{min(levs(k), length(colors))})    end    hold on    if sum,        legstrs{cnt} = ['Sum of levels ' sprintf('%d,',dirdata.levels)];    else        legstrs{cnt} = sprintf('Level %d', levs(k));    end    cnt = cnt + 1;endlegend(ax, legstrs{:},'Location','Best')zoom('reset')set(ax,'Tag',curtag)% plot directions in axes ax using current settingsfunction makedirplot(ax, handles)functype = get(handles.plottype_menu_bottom, 'Value');plottype = (get(handles.polarplot_checkbox, 'Value') == get(handles.polarplot_checkbox, 'Max'));if get(handles.diraverage_checkbox, 'Value') == get(handles.diraverage_checkbox, 'Max'),    avgsize = str2double(get(handles.diraverage_edit,'String'));    if isnan(avgsize)        errordlg('Not a number in direction plot average size edit box','Curvelet viewer error');        avgsize = 1;    endelse    avgsize = 1;endsum = (get(handles.checkbox_sumlevels, 'Value') == get(handles.checkbox_sumlevels, 'Max'));plotdirections(ax, handles.curdirdata, functype, plottype, avgsize, sum);% compute and plot anisotropy measurefunction makeanisoplot(ax, handles)A = crvlt_anisomeas(handles.C);aimg = crvlt_vizaniso(A);cla(ax)axes(ax)imagesc(aimg)axis equal tight, axis offcolorbarcaxis([0 max(aimg(:))])% evaluate image, according to choicefunction imval = funcimag(im, valuetype)switch valuetype,    case 1, % real part        imval = real(im);    case 2, % imag part        imval = imag(im);    case 3, % absolute value        imval = abs(im);    case 4, % log of absolute value        imval = log(abs(im));end% 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}))% call to reinitialize listboxes for new image or new level selection% assumes that handles.im is set to the new/current image% and handles.C to its curvelet transformfunction handles = reinitlistboxes(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 length(handles.C) ~= length(get(handles.listbox_levels,'String')),    str = cell(1,length(handles.C));    for ll=1:length(handles.C)        str{ll} = sprintf('%d',ll);    end    set(handles.listbox_levels,'String',str);    if firstclev > length(handles.C),        % there were more levels in previous image, and only finer levels        % selected => select finest level        set(handles.listbox_levels,'Value',length(handles.C));    else        set(handles.listbox_levels,'Value',oldlevs(oldlevs <= length(handles.C)));    endend% update dirsset(handles.listbox_dirs,'ListboxTop',1);if isempty(firstclev) || firstclev >= length(handles.C),    % only wavelet levels selected, only one dir    str = {'1'};    set(handles.listbox_dirs,'String',str);    set(handles.listbox_dirs,'Value',1);    else    nrdirs = length(handles.C{firstclev});    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    end    set(handles.listbox_dirs,'String',str);    set(handles.listbox_dirs,'Value',dirsel);end% Threshold coefficients according to settingsfunction Cth = threshold_coeffs(C, handles)% C         curvelet coeffs to be thresholded% handles   figure handlesval = str2double(get(handles.edit_thrsh,'String'));if isnan(val) || (val < 0),    errordlg('Bad threshold value','Curvelet viewer error!');    returnendswitch get(handles.menu_thrshtype,'Value'),    case 1, % do nothing        Cth = C;    case 2,  % threshold value        Cth = crvlt_thresh(C, val);        set(handles.edit_curthrsh, 'String', sprintf('# nnz: %d', crvlt_countnnz(Cth)));    case 3,  % number of coeffs        if val <= 0,            Cth = zerodct(C);            smcoef = 0.0;        else            [Cth, smcoef] = crvlt_keeplargest(C, round(val));        end        set(handles.edit_curthrsh, 'String', sprintf('smallest coeff: %f', smcoef));     case 4,  % percentage (assumes val is in [0,1])        if (val > 1 || val <= 0)            errordlg('Bad percentage value. Must be between 0 and 1.','Curvelet viewer error!')        else            [Cth, smcoef] = crvlt_keeplargest(C, val);            set(handles.edit_curthrsh, 'String', sprintf('smallest coeff: %f', smcoef));         endend    % --- Executes on selection change in plottype_menu_top.function plottype_menu_top_Callback(hObject, eventdata, handles)% hObject    handle to plottype_menu_top (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)showinaxis(handles.axes_top, get(handles.displaymenu_top,'Value'), get(handles.menu_plot_curveletpos_top,'Value'), ...    get(handles.plottype_menu_top,'Value'), 1, handles);% --- Executes during object creation, after setting all properties.function plottype_menu_top_CreateFcn(hObject, eventdata, handles)% hObject    handle to plottype_menu_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 selection change in plottype_menu_bottom.function plottype_menu_bottom_Callback(hObject, eventdata, handles)% hObject    handle to plottype_menu_bottom (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)if strcmp(get(handles.showdirdata_tool, 'State'), 'off')    showinaxis(handles.axes_bottom, get(handles.displaymenu_bottom,'Value'), 1, ...        get(handles.plottype_menu_bottom,'Value'), 1, handles);else    makedirplot(handles.axes_bottom, handles)end% --- Executes during object creation, after setting all properties.function plottype_menu_bottom_CreateFcn(hObject, eventdata, handles)% hObject    handle to plottype_menu_bottom (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 menu_imageselect.function menu_imageselect_Callback(hObject, eventdata, handles)% hObject    handle to menu_imageselect (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)N = 512;x=0:1/N:1-10*eps;[X,Y]=meshgrid(x,x);switch get(hObject,'Value'),    case 1, % do nothing            case 2, % load image        loadimage(hObject, handles);        return;    case 3  % disc         Rlg = 0.4;        handles.im = double((X-0.5).^2 + (Y-0.5).^2 < Rlg^2);    case 4 % circle        Rsm = 0.3;        im0 = double((X-0.5).^2 + (Y-0.5).^2 < Rsm^2);        handles.im = ([diff(im0,1,1); zeros(1,N)] + [diff(im0,1,2)  zeros(N,1)]);        handles.im = double(abs(handles.im) > 0);    case 5  % drop        handles.im = eggshape(2, N, [0.5; 0.35], [0.55; 0.7], 0.25, 0.01);    case 6  % front        sl = 2.134;        handles.im = double(sl*X - Y < 0.5);    case 7  % line        sl = 2.134;        width = 0.04;        handles.im = double((sl*X - Y < 0.5+(width/2)) & (sl*X - Y > 0.5-(width/2)));    case 8  % c2-discontinuity        handles.im = exp(-20*((X-0.5).^2 + (Y-0.5).^2));        handles.im(X.^2 + (Y-1).^2 < 0.66^2) = 0.1 * handles.im(X.^2 + (Y-1).^2 < 0.66^2);endif get(handles.checkbox_smooth, 'Value') == get(handles.checkbox_smooth,'Max') ...        && get(hObject,'Value') > 2,    sig2 = (1/N)^2;    gauss=exp(-((X-0.5).^2 + (Y-0.5).^2)/sig2);    handles.im = ifftshift(ifft2(fft2(gauss).*fft2(handles.im))/sum(gauss(:)));endhandles.C = fdct_wrapping(handles.im,0);handles.fim = fftshift(fft2(handles.im));handles = reinitlistboxes(handles);guidata(hObject, handles);handles.stickyaxes = 0;button_go_Callback(hObject, eventdata, handles);% --- Executes during object creation, after setting all properties.function menu_imageselect_CreateFcn(hObject, eventdata, handles)% hObject    handle to menu_imageselect (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 chk_symmetric.function chk_symmetric_Callback(hObject, eventdata, handles)% hObject    handle to chk_symmetric (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hint: get(hObject,'Value') returns toggle state of chk_symmetricfunction edit_curthrsh_Callback(hObject, eventdata, handles)% hObject    handle to edit_curthrsh (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit_curthrsh as text%        str2double(get(hObject,'String')) returns contents of edit_curthrsh as a double% --- Executes during object creation, after setting all properties.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -