首页 > 分享 > matlab 学习之一

matlab 学习之一

关于在自然图像上画散点的操作

显示首先得显示图像

figure

imshow(‘img’) 

hold on %这个很重要,要不然接下来的画图操作就不会画在自然图上了。

for i=1:numel(x)
    a(i) = floor(x(i)/640);
    b(i) = x(i) - a(i)*640;    
end
plot(a,b,'r.');
set(gca,'xlim',[0,639]);   %设置x方向的坐标
set(gca,'ylim',[0,479]);   %设置y方向的坐标
hold off

关于获得图像的句柄(handle)

昨天上网查了好久也没对获得图像的句柄看出个所以然来,忽然灵机一动原来可以这样获得句柄

handle = imshow('img');

然后再对这个句柄去操作。

我接下来的操作是进行鼠标在图像上滑过可以实时显示图像的坐标,

代码如下:

可以采用调用下面的函数来实现这一功能

dypoint(handle); %只需要传递一个参数

(转载的)

function dynpoint(arg,h) 
% Show the coordinates of a plot dynamically 

% To start use: 
% dynpoint(h) 
% where h is a handle to a figure, axes or e.g. line. 

% To delete use: 
% dynpoint('delete',h) 
% where h is a handle to a figure, axes or e.g. line. 
% (you may also use: dynpoint delete) 

% There can only be one dynamic plotter in a figure at a time. 

% Example: 
% subplot(211), hline = plot(sin(1:10)) 
% subplot(212), plot(sin(1:100)) 
% dynpoint(hline) 

% 2002,6.29 

if ~exist('arg','var') 
arg = gcf; 
end 

if ~isstr(arg) 
handle = arg; 
arg = 'init'; 
end 

switch arg 
case 'init' 
if ~ishandle(handle) 
error('h is not a handle') 
end 

[h,ax] = h2hax(handle); 

% delete old dynamic text object 
ht = findobj(h,'tag',[mfilename '_text']); 
if any(ht) 
delete(ht) 
end 

% text window at the bottom left corner 
% text in centred 
uicontrol(h,... 
'style','text',... 
'pos',[2 2 200 15],... 
'tag',[mfilename '_text'],... 
'userdata',ax(1)) 

% do the dynamic thing... 
set(h,'windowbuttonmotionfcn',[mfilename ' move']) 

case 'move' 
ht = findobj(gcbf,'tag',[mfilename '_text']); 
ax = overobj('axes'); 
if ~any(ax) 
ax = get(ht,'userdata'); 
end 
p = get(ax,'currentpoint'); 
set(ht,'string',sprintf('(%g, %g)', p(1), p(3))); 

case 'delete' 
if ~exist('h','var') 
h = gcf; 
end 
[h,ax] = h2hax(h); 
set(h,'windowbuttonmotionfcn','') 

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

end 

% ---------- 
function [h,ax]=h2hax(handle) 

typ = get(handle,'type'); 
if strcmp(typ,'figure') 
h = handle; 
ax = findobj(h,'type','axes'); 
elseif strcmp(typ, 'axes') 
h = get(handle,'parent'); 
ax = handle; 
elseif strcmp( get(get(handle,'parent'), 'type'), 'axes' ) 
ax = get(handle,'parent'); 
h = get(ax,'parent'); 
end

相关知识

MATLAB实现低配电脑的果树病虫害深度学习识别
深度学习之基于Matlab GoogleNet网络的花朵分类识别
MATLAB植物虫害识别
十分钟入门深度学习+MATLAB视频教程+病虫害识别代码+数据集(100%可用)
MATLAB植物叶片虫害识别技术
基于Matlab的农作物叶子病虫害识别与分类
基于Matlab花卉识别分类系统
MATLAB鸢尾花数据集K
MATLAB界面设计全攻略:从基础入门到高级应用
matlab 玫瑰花

网址: matlab 学习之一 https://m.huajiangbk.com/newsview1079947.html

所属分类:花卉
上一篇: 龙骨花繁殖指南,高效繁殖方法全解
下一篇: 方程式(3x+5)/2=(5x