• [脚本无敌1]图片批量处理(matlab)


    分享一些工作中用到的有用脚本,后续还有更多,敬请关注。

    以下代码运行需要matlab环境

    a,图片格式转换

    clear all;clc;close all
    %% bmp->jpg批量转换
    file_list= dir('*.bmp');
    file_num=size(file_list,1);
    if file_num>0
        image_list = {file_list.name};
    else
        error('error:no pic')
    end
    %% process
    disp('start...')
    for ind=1:file_num
        disp(['process...' num2str(round(ind/file_num*100)) '%'])
        filename=cell2mat(image_list(ind));
        a=imread(filename);
        
        %% write
    %     filename=strrep(filename,'png','jpg');
        imwrite(a,filename);
    end
    disp('finish...')
    %%

    b,大小转换

    clear all;clc;close all
    %% 图像大小批量修改为480+大小->小米app上传要求
    file_list= dir('*.png'); % 改变图片类型
    file_num=size(file_list,1);
    if file_num>0
        image_list = {file_list.name};
    else
        error('error:no pic')
    end
    %% process
    disp('start...')
    for ind=1:file_num
        filename=cell2mat(image_list(ind));
        a=imread(filename);
        [row,col,dim]=size(a);
        if row>col
            row=round( row*480/col );
            b=imresize(a,[row 480],'bicubic');
        else
            col=round( col*480/row );
            b=imresize(a,[480 col],'bicubic');
        end
        %% write
        filename=strrep(filename,'png','jpg');
        imwrite(b,filename);
    end
    disp('finish...')
    %%

    好东西,不敢独享,分享之~~

  • 相关阅读:
    高级选项更改MathType数学公式样式
    tp 批量转码
    create the web service by yourshelf
    云通讯 添加群组
    sql 更新字段
    op bug 修复计划
    php ut8声明
    PHP 包含文件
    php 判断查询结果是否为空
    合并列值
  • 原文地址:https://www.cnblogs.com/yemuzi/p/4135346.html
Copyright © 2020-2023  润新知