matlab gui 在鼠标点击时如何返回图像的这一点像素值或颜色值

matlab gui 在鼠标点击时如何返回图像的这一点像素值或颜色值,第1张

方法: 在鼠标点击的毁掉函数中读取坐标像素值 注意图形行列与坐标值的对应关系

function mousepick()

    global I;

    h0 = figure;

    I = imread('2jpg');

    I = rgb2gray(I);

    [m n]=size(I);

    h1 = imshow(I);    

    xlim([0 n-1]);ylim([0 m-1]);

    h2 = uicontrol('style','text','Position',[30 15 100 15],'string','non');

    set(h1,'ButtonDownFcn',@clicky);

    

end

function clicky(varargin) 

    global I;

    a=get(gca,'Currentpoint');

    x = fix(a(1,1));

    y = fix(a(1,2));

    im = I(y,x);

    set(findobj('style','text'),'String',strcat('(',num2str(x),',',num2str(y),')=',num2str(im)  ) );

end

用界面打开图像,并用鼠标左键动态取像素值,右键取消值,并用红色字体显示。哈哈

function varargout = imageaxe(varargin)

% IMAGEAXE M-file for imageaxefig

% IMAGEAXE, by itself, creates a new IMAGEAXE or raises the existing

% singleton

%

% H = IMAGEAXE returns the handle to a new IMAGEAXE or the handle to

% the existing singleton

%

% IMAGEAXE('CALLBACK',hObject,eventData,handles,) calls the local

% function named CALLBACK in IMAGEAXEM with the given input arguments

%

% IMAGEAXE('Property','Value',) creates a new IMAGEAXE or raises the

% existing singleton Starting from the left, property value pairs are

% applied to the GUI before imageaxe_OpeningFcn gets called An

% unrecognized property name or invalid value makes property application

% stop All inputs are passed to imageaxe_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 imageaxe

% Last Modified by GUIDE v25 25-Feb-2012 17:11:05

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename,

'gui_Singleton', gui_Singleton,

'gui_OpeningFcn', @imageaxe_OpeningFcn,

'gui_OutputFcn', @imageaxe_OutputFcn,

'gui_LayoutFcn', [] ,

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_Stategui_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 imageaxe is made visible

function imageaxe_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 imageaxe (see VARARGIN)

% Choose default command line output for imageaxe

handlesoutput = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes imageaxe wait for user response (see UIRESUME)

% uiwait(handlesfigure1);

% --- Outputs from this function are returned to the command line

function varargout = imageaxe_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} = handlesoutput;

varargout{2}=handles;

% --------------------------------------------------------------------

function image_pixel_Callback(hObject, eventdata, handles)

% hObject handle to image_pixel (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% --------------------------------------------------------------------

function m_file_open_Callback(hObject, eventdata, handles)

% hObject handle to m_file_open (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

global I hText

[filename, pathname] = uigetfile(

{'bmp;jpg;png;jpeg', 'Image Files ';

'','All Files'}, 'test',

'D:\autostitch\images\test');

%用axes命令设定当前 *** 作的坐标轴是axes_src

I=[pathname,filename];%将文件名和目录名组合成一个完整的路径

F= imread(I);%用imread读入

axes(handlesaxes1_src);

imshow(F);

impixelinfo; % or you can use pixval;

[x y]=ginput(1); % when you clike mouse, [x y] respond its image coordination

global pointXY

pointXY=[];

set(gcf,'WindowButtonDownFcn',@WindowButtonDownFcn);

%set(gcf,'KeyPressFcn',@KeyPressFcn);

function WindowButtonDownFcn(hObject, eventdata, handles)

%if strcmp(get(hObject,'SelectionType'),'normal')

global pointXY

global hText

if strcmp(get(hObject,'SelectionType'),'normal')

pt = get(gca,'CurrentPoint'); % 如何限制鼠标获得图像的坐标,不要空白处坐标。

x = pt(1,1);

y = pt(1,2);

str = sprintf('x = %3f, y = %3f', x, y);

hText=text(x, y, str,'color',[1 0 0]);

pointXY=[pointXY;[x y]];

elseif strcmp(get(hObject,'SelectionType'),'alt')

if ishandle(hText)

delete(hText);

pointXY(end,:)=[];

end

end

%elseif strcmp(get(hObject,'SelectionType'),'alt')

% if ishandle(hText)

% delete(hText);

% pointXY(end,:)=[];

% end

%end

%function KeyPressFcn(hObject, eventdata, handles)

%global pointXY

%key=get(hObject,'currentkey');

%switch key

% case 'return'

%xlswrite('1xls',pointXY);

% msgbox('采集的点已经保存到1xls文件中!');

%end

% hText=text(x, y, 'string','color',[1 0 0]);

%ht=findobj(handlestext2,'tag',[x y]);

% set(handlestext2,'string', hText)

%ht = findobj(h,'tag',[mfilename '_text']);

%set(handlestext2,'string',strcat(num2str(x),',',num2str(y)))

%set(gcf,'WindowButtonDownFcn',@ButttonDownFcn);

% 回调函数

%function ButttonDownFcn(src,event)

%pt = get(gca,'CurrentPoint');

%x = pt(1,1);

%y = pt(1,2);

%pointXY=[];

%fprintf('x=%f,y=%f\n',x,y);

% pt = get(gca,'CurrentPoint');

% x = pt(1,1);

% y = pt(1,2);

% str = sprintf('x = %3f, y = %3f', x, y);

%set(handlestext2,'string', str);

% save

% --- Executes during object creation, after setting all properties

function axes1_src_CreateFcn(hObject, eventdata, handles)

% hObject handle to figure1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% --------------------------------------------------------------------

function m_file_quit_Callback(hObject, eventdata, handles)

% hObject handle to m_file_quit (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

close

function edit1_Callback(hObject, eventdata, handles)

% hObject handle to edit1 (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 edit1 as text

% str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit1 (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

% --------------------------------------------------------------------

function m_file_save_Callback(hObject, eventdata, handles)

% hObject handle to m_file_save (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

[FileOutName,FileOutPath]=uiputfile('m','Save file name','C:\Documents and Settings\Administrator\桌面\matlab\第二周\mouse_axem');

%StrFileOut=strcat(FileOutPath,FileOutName)

%hgsave(gcf,' imageaxefig')

以上就是关于matlab gui 在鼠标点击时如何返回图像的这一点像素值或颜色值全部的内容,包括:matlab gui 在鼠标点击时如何返回图像的这一点像素值或颜色值、matlab中如何根据点的索引获得点的坐标、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/10157322.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存