matlab的图片上如何画线,如何在照片上画线?

本人做了一个GUI界面,目标是实现在axes坐标中导入一张照片,然后可以在照片上用鼠标画圈,然后就可以计算出画圈部分占照片总面积的比例;同时也可以用白色覆盖多余部分(可以看成橡皮擦功能吧?)

但目前:画圈,橡皮擦功能的代码是基于axes坐标轴实现的,也就是说,实际上照片本身并没有改变,画的圈只是和照片在一个坐标中同时显示出来而已,如果保存照片的话,画的圈和擦掉的部分都不会在保存的照片中体现。。。我该怎么改?先谢过了!下面是画圈,和橡皮擦的功能的代码。。。其实本质是一样的

19b0fe3299812d8066e982a21c3cbca5.gif

function figure_EasyPaint_WindowButtonDownFcn(hObject, eventdata, handles)

% hObject    handle to figure_EasyPaint (see GCBO)

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

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

global flag x0 y0 x y PaintFlag Eflag;

flag = 1;     %鼠标单击

cp = get(handles.axes_before, 'CurrentPoint');         %axes_before 为坐标轴Tag

x = cp(1,1);

y = cp(1,2);

if PaintFlag    % 选择画圈按钮

plot(handles.axes_before, x, y, 'Color', [1 0 0]);

end

if Eflag       %选择橡皮擦按钮

set(gcf, 'CurrentAxes', handles.axes_before);

plot(handles.axes_before, x, y, 'Color', [1 1 1]);

end

x0 = x;

y0 = y;

guidata(hObject, handles);

% --- Executes on mouse motion over figure - except title and menu.

function figure_EasyPaint_WindowButtonMotionFcn(hObject, eventdata, handles)

% hObject    handle to figure_EasyPaint (see GCBO)

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

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

global flag x0 y0 x y PaintFlag Eflag;

x0 = x;

y0 = y;

cp = get(handles.axes_before, 'CurrentPoint');

x = cp(1,1);

y = cp(1,2);

if flag && PaintFlag

temp = get(handles.slider1, 'Value');

LineWidth = temp + 2;

plot(handles.axes_before, [x0 x], [y0 y], 'LineWidth', LineWidth, 'Color', [1 0 0]);

end

if flag && Eflag

set(gcf, 'CurrentAxes', handles.axes_before);

temp = get(handles.slider1, 'Value');

LineWidth = temp + 2;

plot(handles.axes_before, [x0 x], [y0 y], 'LineWidth', LineWidth, 'Color', [1 1 1]);

end

guidata(hObject, handles);

% --- Executes on mouse press over figure background, over a disabled or

% --- inactive control, or over an axes background.

function figure_EasyPaint_WindowButtonUpFcn(hObject, eventdata, handles)

% hObject    handle to figure_EasyPaint (see GCBO)

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

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

global flag PaintFlag Eflag;

flag = 0;

PaintFlag = 0;

Eflag = 0;

guidata(hObject, handles);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值