前言
此文章会涉及常用的画图函数和技巧,包括1维/2维/3维数据。 文章会一直更新。
2维图片
图像分割成不同的patches
27.08.2021
最近在尝试ViT模型,在可视化输入数据时需要把图片分割成若干部分(patches)。示例图片如下,
代码如下:
%% load image
uiopen(' earth.jpeg',1)
earth_gray = rgb2gray(earth); % 转换成灰度图片
figure;imagesc(earth_gray)
whos earth_gray
%% cutout 剪切
earth_gray_cutout = earth_gray;
earth_gray_cutout(1:30,:) = [];
earth_gray_cutout(end-10:end,:) = [];
earth_gray_cutout(:,1:50) = [];
earth_gray_cutout(:,end-20: end) = [];
figure;imagesc(earth_gray_cutout)
whos earth_gray_cutout
%% resize 大小变成 400 X 400
image_size = 400;
earth_gray_cutout_resize = imresize(earth_gray_cutout,[image_size image_size]);
%% divide the image into several patches
template_image =