MATLAB将多张小图整合到一张大图形成模板图

MATLAB将多张小图整合到一张大图形成模板图

代码如下:

clc;close all;clear all;warning off;%清除变量
rand('seed', 100);
randn('seed', 100);
format long g;


foldername='字符模板';
[datacell,filenamecell,filenameAllcell]=readfun_1n(foldername);
K2=length(filenamecell);

% 设置网格大小和每个图像的大小
gridSize = [10,6]; % 网格,你可以根据需要调整
imageSize = [20 40]; % 每个图像的大小,你也可以调整

% 创建一个大的空白图像来放置所有小图像
outputImageSize = gridSize .* imageSize;
outputImage = uint8(zeros(outputImageSize(1), outputImageSize(2)));

% 遍历所有图像文件并将它们放到网格中
for i = 1:K2
    % 读取图像并调整大小
    img = datacell{i,1};
    img = imresize(img, imageSize);
    
    % 计算图像在网格中的位置
    [row, col] = ind2sub(gridSize, i);
    rowStart = (row - 1) * imageSize(1) + 1;
    rowEnd = row * imageSize(1);
    colStart = (col - 1) * imageSize(2) + 1;
    colEnd = col * imageSize(2);
    
    % 将图像放到大图像中的正确位置
    outputImage(rowStart:rowEnd, colStart:colEnd) = img;
end

% 显示和保存结果
figure;
imshow(outputImage);
imwrite(outputImage, 'output.jpg'); % 你可以更改输出文件的名称和类型


程序结果:

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-24 09:10:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-24 09:10:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-24 09:10:05       87 阅读
  4. Python语言-面向对象

    2024-04-24 09:10:05       96 阅读

热门阅读

  1. 146. LRU 缓存

    2024-04-24 09:10:05       31 阅读
  2. windows驱动开发-I/O请求(二)

    2024-04-24 09:10:05       29 阅读
  3. Linux内核驱动开发-006内核定时器

    2024-04-24 09:10:05       33 阅读
  4. c#版本LabelMe标注辅助工具源码

    2024-04-24 09:10:05       33 阅读
  5. [SP10606] BALNUM - Balanced Numbers 解题记录

    2024-04-24 09:10:05       37 阅读
  6. 算法题解记录21+++打家劫舍(百日筑基)

    2024-04-24 09:10:05       33 阅读
  7. kafak知识总结(2)

    2024-04-24 09:10:05       33 阅读
  8. 对React-Fiber的理解,它解决了什么问题?

    2024-04-24 09:10:05       37 阅读
  9. 网站安全方案

    2024-04-24 09:10:05       28 阅读
  10. 阿里云域名动态解析

    2024-04-24 09:10:05       32 阅读
  11. 使用python写一个井字棋窗口小游戏

    2024-04-24 09:10:05       34 阅读