我是靠谱客的博主 懵懂耳机,最近开发中收集的这篇文章主要介绍MATLAB画框,并把框起来的保存,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

first.m

% ------------------
%
Matlab手动鼠标截图,获取兴趣区域
% ------------------
clc;
clear;
close all;
pathname = 'E:first_ideatest72img_072_x4_our.png';
origin_img = imread(pathname);
figure;
imshow(origin_img,[]);
title('Original Image');
% 画图后,将鼠标变成十字架,用来选择兴趣区域
h = imrect;
% 拖动鼠标获得兴趣区域,pos有四个值,兴趣区域左上角的像素坐标和区域的长宽
position = getPosition(h);
%[x,y] = ginput(2);
[m, n, z] = size(origin_img);
start_y= floor(position(2));
start_x=floor(position(1));
rect_size_y=floor(position(3));
rect_size_x=floor(position(4));
s=draw_rect(origin_img, [start_y,start_x],[rect_size_y, rect_size_x], 3, [255, 0, 0]);
imwrite(s,'E:first_ideakuangimg_072_x4_our.png')

second.m

%strarr = ['bicubic.png';'CARN.png';'DRCN.png';'DRRN.png';'FSRCNN.png';'GT.png';'LapSRN.png';'our.png';'SRCNN.png';'VDSR.png';'ZHUKAI.png'];
pathname1 = ['E:first_ideatest72img_072_x4_','ZHUKAI.png'];
origin_img = imread(pathname1);
ROI = imcrop(origin_img,position);
imwrite(ROI,['E:first_ideatest72','ZHUKAI.png'],'png');

draw_rect.m

function [ dest ] = draw_rect(src, startPosition, rectSize, lineSize, color)
[start_y, start_x] = deal(startPosition(1),startPosition(2));
% start position
[rect_size_w, rect_size_h] = deal(rectSize(1),rectSize(2));
% Rect Size
[width, height, channel] = size(src);
if channel==1
dest(:, : ,1) = src;
dest(:, : ,2) = src;
dest(:, : ,3) = src;
else
dest = src;
end
for channel_i = 1 : 3
for line_i = 1 : lineSize
% expand inside
gain = line_i-1;
dest(start_y+gain, (start_x+gain):(start_x+rect_size_w-gain),
channel_i ) =
color(channel_i);
%above
dest(start_y+rect_size_h-gain,
(start_x+gain):(start_x+rect_size_w-gain), channel_i ) =
color(channel_i);	%bottom
dest((start_y+gain):(start_y+rect_size_h-gain),
start_x+gain, channel_i ) =
color(channel_i);
%left
dest((start_y+gain):(start_y+rect_size_h-gain),
start_x+rect_size_w-gain, channel_i ) =
color(channel_i);	%right
end
end

最后

以上就是懵懂耳机为你收集整理的MATLAB画框,并把框起来的保存的全部内容,希望文章能够帮你解决MATLAB画框,并把框起来的保存所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部