自己在做图像处理,灰度图像转数据,并处理信号时写的代码,主要功能是将CIS,在1s90帧的频率下,采集的几千张灰度图批量转为矩阵数据,并for循环迭代,分别计算出每张图中的灰度值总和(作为图片信号值),然后输出xy波形图,并将其输出数据保存在excel中。
新手代码,也是综合了网上的一些方法,希望能给大家提供些思路。
clc
clear
file_path = 'D:\data\xx图\'; % define information
img_path_list = dir(strcat(file_path,'*.bmp'));
img_num = length(img_path_list);
S = cell(img_num,1);
Y = [];
new_folder = 'D:\data\xx图\数据'; % make new folder
mkdir(new_folder);
addpath(new_folder);
for i = 1 : img_num
img_name = img_path_list(i).name; % choose&read image
fprintf('%d %s\n',i,strcat(file_path,img_name));
A = imread(strcat(file_path,img_name)); % transform image(i)
temp1 = reshape(A,1,[]);
S{i,1} = temp1;
temp2 = sum(temp1,2);
Y(i,1) = temp2
end
x = linspace(0,50/3,1500);
y = Y;
plot(x,y,'-r*')
F = plot(x,y,'-r*');
path = cd;
xlswrite('D:\data\xx图\数据\data.xls',Y);
imwrite(F,'D:\data\x图\数据\data.jpg');