matlab在图片上写字后保存

本文演示了如何使用MATLAB在图像上添加文本。通过vision.TextInserter函数实现文本插入,并展示了添加文本前后的图像对比。适用于初学者了解基本的图像处理技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. close all
  2. clc
  3. I=imread('cameraman.tif');
  4. ti=vision.TextInserter('Test', 'Location', [30 30],'FontSize', 12);
  5. J=step(ti,I);
  6. figure
  7. subplot(121),imshow(I),title('原始图像')
  8. subplot(122),imshow(J),title('处理后图像,此图像可imwrite')
以上转载自 http://www.ilovematlab.cn/thread-263887-1-1.html
以下是一个基本的Matlab写字板程序,可以创建一个GUI界面,允许用户在画板上绘制,使用鼠标保存所画的图片。 ``` function myPaint % Create a GUI with drawing canvas and save button % Create a new figure window hFig = figure('Toolbar','none',... 'Menubar', 'none',... 'NumberTitle','off',... 'Name','Paint',... 'Units','normalized',... 'Position',[0.2 0.2 0.6 0.6]); % Create a new drawing canvas hAx = axes('Parent',hFig,... 'Units','normalized',... 'Position',[0.05 0.05 0.9 0.85],... 'XLim',[0 1],'YLim',[0 1],... 'XTick',[],'YTick',[],... 'Color',[1 1 1]); % Create a save button hButton = uicontrol('Parent',hFig,... 'Style','pushbutton',... 'String','Save',... 'Units','normalized',... 'Position',[0.4 0.92 0.2 0.05],... 'Callback',@saveButton_Callback); % Initialize the drawing state drawing = false; lastPoint = []; % Define the callback function for mouse button down set(hAx,'ButtonDownFcn',@startDrawing); % Define the callback function for mouse movement set(hFig,'WindowButtonMotionFcn',@drawLine); % Define the callback function for mouse button up set(hFig,'WindowButtonUpFcn',@stopDrawing); % Callback function for mouse button down function startDrawing(hObject, eventdata) drawing = true; lastPoint = get(hAx,'CurrentPoint'); lastPoint = lastPoint(1,1:2); end % Callback function for mouse movement function drawLine(hObject, eventdata) if drawing currentPoint = get(hAx,'CurrentPoint'); currentPoint = currentPoint(1,1:2); line([lastPoint(1) currentPoint(1)], [lastPoint(2) currentPoint(2)],... 'Color','k','LineWidth',2); lastPoint = currentPoint; end end % Callback function for mouse button up function stopDrawing(hObject, eventdata) drawing = false; end % Callback function for save button function saveButton_Callback(hObject, eventdata) [filename, pathname] = uiputfile({'*.png';'*.jpg';'*.bmp';'*.tif'},'Save As'); if isequal(filename,0) || isequal(pathname,0) return; end print(hFig, fullfile(pathname, filename), '-dpng', '-r300'); end end ``` 运行此程序后,您可以使用鼠标在画板上绘制任何图形。点击保存按钮将弹出文件对话框,允许您选择要保存的文件类型和位置。程序将绘图保存为PNG,JPG,BMP或TIF格式中的一个。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值