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