Semester assignments for the course "Digital Image Processing" of THMMY in AUTH university.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

function saveasppm(x, filename, K)
%saveasppm encodes an image as PPM and saves it to the disk
% Usage saveasppm(x, filename, K), where:
% Inputs
% - x is the input image
% - filename is the path and filename of the file where the resulting
% PPM image is going to be saved
% - K is the maximum value of brightness
file = fopen(filename, 'wt+');
fwrite(file, 'P6');
fwrite(file, ' ');
fwrite(file, int2str(size(x.red, 1)));
fwrite(file, ' ');
fwrite(file, int2str(size(x.red, 2)));
fwrite(file, ' ');
fwrite(file, int2str(K));
fwrite(file, newline);
if K < 256
precision = 'integer*1';
precisionBytes = 1;
machinefmt = 'l';
else
precision = 'integer*2';
precisionBytes = 2;
machinefmt = 'b';
end
for row = 1:size(x.red, 1)
for column = 1:size(x.red, 2)
fwrite(file, x.red(row, column), precision, machinefmt);
fwrite(file, ' ');
fwrite(file, x.green(row, column), precision, machinefmt);
fwrite(file, ' ');
fwrite(file, x.blue(row, column), precision, machinefmt);
fwrite(file, ' ');
end
end
% combined = B(:,[1;1]*(1:size(B,2)));
% combined(:,1:2:end) = A;
fclose(file);
end