matlab 读取txt数据并保存为图像

clear all;

width=640;

height=480;

data_ori = importdata('orbbec_dep_pic0.txt');

data_out = zeros(height, width);

depth_out = zeros(height, width);

[row_length, col_length] =size(data_ori);

disp(col_length);

j=0;

 

for count=0:col_length-1

    i = mod(count, width);

    j = fix(count / width);

    data_out(j + 1, i + 1) = data_ori(count + 1);

end

 

clear data_ori;

 

for j = 1:height

    for i = 1:width

        if (data_out(j, i) > 10)

            disp('err point');

        end

        if (data_out(j, i) > 0)

            depth_out(j, i) = (1 - data_out(j, i) / 10) * 256;

        end

    end

end

 

depth_out = uint8(depth_out);

imshow(depth_out);

imwrite(depth_out, 'test.jpg');


你可能感兴趣的:(matlab)