注意:这篇文章上次更新于1243天前,文章内容可能已经过时。
用于从图像中抠出一部分来绘制这种细节对比图
我怕我把代码弄丢,所以记下来。
- retanc.m
clear;close all; clc;
file_name = 'zxs2015_120721.jpg';
I = imread(file_name);
I = im2double(I);
set(gcf,'CurrentCharacter','@'); % set to a dummy character
figure(1),imshow(I);
disp('Please select the region on the image.');
[x1,y1] = ginput(2);
% x1 = [286;520];
% y1 = [783;1006];
% set(gcf,'CurrentCharacter','@'); % set to a dummy character
% figure(1),imshow(I);
% disp('Please select the region on the image.');
% [x2,y2] = ginput(2);
I_tmp = insertShape(I, 'Rectangle', [x1(1),y1(1),x1(2)-x1(1),y1(2)-y1(1)], 'LineWidth',5, 'Color', 'red');
% I_tmp = insertShape(I_tmp, 'Rectangle', [x2(1),y2(1),x2(2)-x2(1),y2(2)-y2(1)], 'LineWidth', 5, 'Color', 'red');
figure(2),imshow(I_tmp);
I_cut1 = I(y1(1):y1(2),x1(1):x1(2),:);
% I_cut2 = I(y2(1):y2(2),x2(1):x2(2),:);
figure(3),imshow(I_cut1);
% figure(4),imshow(I_cut2);
imwrite(I_tmp,[file_name(1:end-4),'_cut.jpg']);
imwrite(I_cut1,[file_name(1:end-4),'_cut1.jpg']);
% imwrite(I_cut2,[file_name(1:end-4),'_cut2.jpg']);
save([file_name(1:end-4),'.mat']);
- retanc_load.m
clear;close all; clc;
load('5.mat');
file_name = '5.png';
I = imread(file_name);
I = im2double(I);
I_tmp = insertShape(I, 'Rectangle', [x1(1),y1(1),x1(2)-x1(1),y1(2)-y1(1)], 'LineWidth', 5, 'Color', 'blue');
% I_tmp = insertShape(I_tmp, 'Rectangle', [x2(1),y2(1),x2(2)-x2(1),y2(2)-y2(1)], 'LineWidth', 5, 'Color', 'red');
figure(2),imshow(I_tmp);
I_cut1 = I(y1(1):y1(2),x1(1):x1(2),:);
% I_cut2 = I(y2(1):y2(2),x2(1):x2(2),:);
figure(3),imshow(I_cut1);
% figure(4),imshow(I_cut2);
imwrite(I_tmp,[file_name(1:end-4),'_cut.jpg']);
imwrite(I_cut1,[file_name(1:end-4),'_cut1.jpg']);
% imwrite(I_cut2,[file_name(1:end-4),'_cut2.jpg']);