MATLAB 图像RGB转Lab并进行Min-Max归一化存成图片,原始的Lab数据存入Excel

MATLAB 图像RGB转Lab并进行Min-Max归一化存成图片,把数据保存到Excel文件中,更方便对比查看,经过一番search解决了一个表格多个sheet存放数据和更改sheet名的问题。

clc;
clear;
close all;

PATH = 'C:\Users\UserName\Desktop\Img_20200509\';
fileFolder=fullfile(PATH);
dirOutput=dir(fullfile(fileFolder,'*.jpg'));

[size_1, size_2] = size(dirOutput);


e = actxserver('Excel.Application');     % open Activex server

for index=1:size_1
    file_name = dirOutput(index).name;
    dir_name = strsplit(file_name, '.');
    dir_name = cell2mat(dir_name(1));
    disp(dir_name);
    mkdir(PATH, dir_name);

    img_rgb = imread(strcat(PATH, file_name));
    img_lab = rgb2lab(img_rgb);
    img_path = strcat(PATH, dir_name);
    imwrite(mat2gray(img_lab(:,:,1)), strcat(img_path, '\L.jpg'));
    imwrite(mat2gray(img_lab(:,:,2)), strcat(img_path, '\a.jpg'));
    imwrite(mat2gray(img_lab(:,:,3)), strcat(img_path, '\b.jpg'));

    xlswrite(strcat(img_path, '\Lab.xlsx'),img_lab(:,:,1), 1);
    xlswrite(strcat(img_path, '\Lab.xlsx'),img_lab(:,:,2), 2);
    xlswrite(strcat(img_path, '\Lab.xlsx'),img_lab(:,:,3), 3);

    ewb = e.Workbooks.Open(strcat(img_path, '\Lab.xlsx')); 
    ewb.Worksheets.Item(1).Name = 'L';                                % rename sheet 1                                       
    ewb.Worksheets.Item(2).Name = 'a'; 
    ewb.Worksheets.Item(3).Name = 'b'; 

    ewb.Save;                       % save to the same file
    ewb.Close(false);
    
end

e.Quit
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值