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

📄 imgaliasexpofn.m

📁 非常好的数字处理教程
💻 M
字号:
%function imgaliasexpofn(action,datastruct)if nargin < 1	action='init';end% When not keep size, scaling wrong for kernelname = mfilename;figname = [name(1:end-2) '_fig'];f=findobj('Tag',figname);handles = get(f,'UserData');switch action	case 'help'		display_help(figname);	case 'init'		reset(handles.spectrum);		setdefaults;	case 'load'		handles.imagedata = load_imagedata;		set(handles.downsample,'Value',1);		if ~isfield(handles.imagedata, 'filenamepath')			return;		elseif isfield(handles,'figwin');			try,				close(handles.figwin);			catch			end		end		handles.original = handles.imagedata;		make2DSpecPlot(handles.imagedata, handles);		handles.figwin = showimage(handles.imagedata, ...			get(handles.scale,'Value'), get(handles.inverse,'Value'));		place_header(handles.figwin, handles);		movegui(handles.figwin,'onscreen');	case 'readinput'		handles.imagedata = datastruct;		clear datastruct		reset(handles.spectrum);		setdefaults;		set(handles.downsample,'Value',1);		handles.original = handles.imagedata;		make2DSpecPlot(handles.imagedata,handles);		handles.figwin = showimage(handles.imagedata, ...			get(handles.scale,'Value'), get(handles.inverse,'Value'));		place_header(handles.figwin, handles);		movegui(handles.figwin,'onscreen');	case {'scale','inverse'}		if isfield(handles, 'imagedata')			figure(handles.figwin);			X = get(gca, 'XLim');			Y = get(gca, 'YLim');			showimage(handles.imagedata, get(handles.scale,'Value'), get(handles.inverse,'Value'), handles.figwin);			set(gca,'XLim',X,'YLim',Y);		end	case {'colormap','inversecolor'}		if isfield(handles, 'imagedata')			figure(handles.imgaliasexpo_fig);			axes(handles.spectrum);			contents = get(handles.colormap,'String');			cmap = colormap(lower(contents{get(handles.colormap,'Value')}));			if (get(handles.inversecolor,'Value'))				colormap(flipud(cmap));			else				colormap(cmap);			end		end	case 'downsample'		if isfield(handles, 'imagedata')			contents = get(handles.downsample,'String');			downfactor = str2num(contents{get(handles.downsample,'Value')});			if get(handles.horizontal,'Value')				type = 'horizontal';			elseif get(handles.vertical,'Value')				type = 'vertical';			else				type = 'kernel';			end			keepsize = get(handles.keepsize,'Value');			figure(handles.figwin);			X = get(gca, 'XLim');			Y = get(gca, 'YLim');			handles.imagedata_alias = downsample(handles.imagedata, ...				downfactor, get(handles.antialias,'Value'), type, keepsize);			make2DSpecPlot(handles.imagedata_alias, handles);			showimage(handles.imagedata_alias, get(handles.scale,'Value'), ...				get(handles.inverse,'Value'),handles.figwin);			movegui(handles.figwin,'onscreen');		end	case 'zoom_reset'		if isfield(handles, 'imagedata_alias')			showimage(handles.imagedata_alias, get(handles.scale,'Value'), get(handles.inverse,'Value'), handles.figwin);		end	case 'plot'		[rows,columns] = size(handles.imagedata.data);		contents = get(handles.filtermenu,'String');		kernel_size = str2double(get(handles.kernel_size,'String'));		switch (lower(contents{get(handles.filtermenu,'Value')}))			case 'median'				% Cannot plot frequency response			otherwise		end	case {'imgspecexpo','imgfilterexpo'}		if isfield(handles,'imagedata')			imagedata = handles.imagedata;			switch action				case 'imgspecexpo'					imgspectrumexpogui(imagedata);				case 'imgfilterexpo'					imgfilterexpogui(imagedata);			end		end	case 'save'		save_imagedata(handles.imagedata_alias);	case 'print'		print_figure(f);	case 'close'		close_figure(f,figname(1:end-4));		if isfield(handles, 'figwin'),			close_figure(handles.figwin);		end		return;endset(f,'UserData',handles);%-------------------------------------------------------------function make2DSpecPlot(imagedata,handles)figure(handles.imgaliasexpo_fig);axes(handles.spectrum);spectrum = log(abs(fftshift(fft2(imagedata.data))));% Get rid of infpoints = isinf(spectrum);spectrum(points) = 0;imagesc(spectrum);contents = get(handles.colormap,'String');cmap = colormap(lower(contents{get(handles.colormap,'Value')}));if (get(handles.inversecolor,'Value'))	colormap(flipud(cmap));else	colormap(cmap);endaxis image;%-------------------------------------------------------------function imagedata = downsample(imagedata,factor,antialias,varargin)if nargin<4,	type = 'kern';	keepsize = 0;elseif nargin<5	type = varargin{1};	keepsize = 0;elseif nargin<6	type = varargin{1};	keepsize = varargin{2};end% Lowpass imageif antialias,	imagedata.data = imresize(imagedata.data,1/factor,'bilinear',10);	imagedata.data = imresize(imagedata.data,factor);end[rows,columns] = size(imagedata.data);k = floor(factor/2);% Create place to store valuesA = zeros(rows+2*k,columns+2*k);% Put the original image in the centerA(k+1:rows+k,k+1:columns+k) = imagedata.data;% Four cornersA(1:k,1:k) = imagedata.data(1,1);A(1:k,columns+k+1:columns+2*k) = imagedata.data(1,columns);A(rows+k+1:rows+2*k, columns+k+1:columns+2*k) = ...	imagedata.data(rows,columns);A(rows+k+1:rows+2*k,1:k) = imagedata.data(rows,1);% Handle the four sidesfor i = 1:k	A(i,k+1:columns+k) = imagedata.data(1,1:columns);	A(k+1:rows+k,columns+k+i) = ...		imagedata.data(1:rows,columns);	A(rows+k+i,k+1:columns+k) = ...		imagedata.data(rows,1:columns);	A(k+1:rows+k,i) = imagedata.data(1:rows,1);endif keepsize	B = zeros(rows,columns);	switch type		case 'horizontal'			for i=1:rows,				for j=1:columns,					B(i,j) = A(i+k,floor((j-1)/factor)*factor+1+2*k);				end			end		case 'vertical'			for i=1:rows,				for j=1:columns,					B(i,j) = A(floor((i-1)/factor)*factor+1+2*k,j+k);				end			end		case 'kernel'			for i=1:rows,				for j=1:columns,					B(i,j) = A(floor((i-1)/factor)*factor+1+2*k,floor((j-1)/factor)*factor+1+2*k);				end			end	endelse	switch type		case 'horizontal'			B = zeros(rows,floor(columns/factor));			for i=1:rows,				for j=1:floor(columns/factor),					B(i,j) = A(i+k,(j-1)*factor+1+2*k);				end			end		case 'vertical'			B = zeros(floor(rows/factor),columns);			for i=1:floor(rows/factor),				for j=1:columns,					B(i,j) = A((i-1)*factor+1+2*k,j+k);				end			end		case 'kernel'			B = zeros(floor(rows/factor),floor(columns/factor));			for i=1:floor(rows/factor),				for j=1:floor(columns/factor),					B(i,j) = A((i-1)*factor+1+2*k, (j-1)*factor+1+2*k);				end			end	endendimagedata.data = B;

⌨️ 快捷键说明

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