转载-图片分块

转载自:https://blog.csdn.net/jizhidexiaoming/article/details/84036665
感谢博主:Mr.Q
一,不重叠分块

效果:
在这里插入图片描述
在这里插入图片描述
代码:

clear;
clc;
 
img = imread('/media/P1.jpg');
%img=imread('rice.png');%自带图片
 
%% resize the image into the new size with 500x*500y
r_img = img(:, :, 1);
g_img = img(:, :, 2);
b_img = img(:, :, 3);
[row, col] = size(r_img);
new_row = ceil(row/500) * 500;%500是子块的row
new_col = ceil(col/500) * 500;%500是子块的col
new_r_img = imresize(r_img, [new_row new_col], 'bilinear');
new_g_img = imresize(g_img, [new_row new_col], 'bilinear');
new_b_img = imresize(b_img, [new_row new_col], 'bilinear');
new_img(:, :, 1) = new_r_img;
new_img(:, :, 2) = new_g_img;
new_img(:, :, 3) = new_b_img;
 
[y_row y_col dim] = size(new_img);
row_blk_num = y_row/500;  % 3
col_blk_num = y_col/500;  % 6
 
 
no overlap
blocks = 1;
for i = 1:row_blk_num
    for j = 1:col_blk_num
        disp(blocks);
        block = new_img((i - 1) * 500 + 1 : i * 500, (j - 1) * 500 + 1 : j * 500, :);
        imwrite(block, ['./' num2str(blocks) '.jpg']);
        blocks = blocks + 1;
    end
end

二,重叠(重叠大小为块的一半)

效果(部分)
在这里插入图片描述
代码:

clear;
clc;
 
img = imread('/media/P1.jpg');
 
%% resize the image into the new size with 16x*16y
r_img = img(:, :, 1);
g_img = img(:, :, 2);
b_img = img(:, :, 3);
[row, col] = size(r_img);
new_row = ceil(row/500) * 500;
new_col = ceil(col/500) * 500;
new_r_img = imresize(r_img, [new_row new_col], 'bilinear');
new_g_img = imresize(g_img, [new_row new_col], 'bilinear');
new_b_img = imresize(b_img, [new_row new_col], 'bilinear');
new_img(:, :, 1) = new_r_img;
new_img(:, :, 2) = new_g_img;
new_img(:, :, 3) = new_b_img;
 
 
[y_row y_col dim] = size(new_img);
row_blk_num = (y_row-250)/250;  % 5
col_blk_num = (y_col-250)/250;  % 11
 
 
blocks = 1;
for i = 1:row_blk_num
    for j = 1:col_blk_num
        disp(blocks);
        block = new_img((i - 1) * 250 + 1 : (i+1) * 250, (j - 1) * 250 + 1 : (j+1) * 250, :);
        imwrite(block, ['./' num2str(blocks) '.jpg']);
        blocks = blocks + 1;
    end
end
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
el-upload组件支持分块上传大文件,可以使用chunk-upload属性来启用分块上传。以下是一个上传大小超过60M的大幅图片的el-upload组件分块上传的示例代码: ```html <template> <el-upload class="upload-demo" action="/upload" :on-exceed="handleExceed" :before-upload="beforeUpload" :chunk-upload="true" :chunk-size="5 * 1024 * 1024" :limit-size="100000000" :file-list="fileList" multiple> <el-button size="small" type="primary">点击上传</el-button> <div slot="tip" class="el-upload__tip">只能上传不超过 100MB 的文件</div> </el-upload> </template> <script> export default { data() { return { fileList: [] } }, methods: { handleExceed(files, fileList) { this.$message.warning(`文件数量超过限制,只能上传一个文件`); }, beforeUpload(file) { const isJPG = file.type === 'image/jpeg'; const isLt100M = file.size / 1024 / 1024 < 100; if (!isJPG) { this.$message.error('上传图片只能是 JPG 格式!'); } if (!isLt100M) { this.$message.error('上传图片大小不能超过 100MB!'); } return isJPG && isLt100M; } } } </script> ``` 在上面的代码中,我们通过设置chunk-upload属性来启用分块上传,并设置chunk-size属性来设置每个分块的大小。这里我们设置每个分块的大小为5MB,可以根据实际情况进行调整。同时,在beforeUpload方法中对上传的文件进行了格式和大小的判断,如果不符合要求则会弹出提示框。如果需要上传的文件数量超过限制,则会触发handleExceed方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值