MATLAB Answers

How can I covert serious of grey scale images to jet images

7 views (last 30 days)
SHILPA S
SHILPA S on 13 Apr 2021 at 6:55
Answered: Walter Roberson on 13 Apr 2021 at 7:37
I would like to know the coding for coversion of serious of grey scale images to jet color

Answers (1)

Walter Roberson
Walter Roberson on 13 Apr 2021 at 7:37
in_ext = '.png';
out_ext = '.png';
projectdir = 'path/to/files'; %can be '.'
outdir = 'path/to/store/output'; %must be different if in_ext and out_ext are the same
if ~exist(outdir, 'dir')
mkdir(outdir);
end
cmap = jet(256);
dinfo = dir(fullfile(projectdir, ['*' in_ext]));
filenames = fullfile({dinfo.folder}, {dinfo.name});
nfiles = length(filenames);
for K = 1 : nfiles
thisfile = filenames{K};
[~, basename, ~] = fileparts(thisfile);
outfile = fullfile(outdir, [basename out_ext]);
if strcmp(thisfile, outfile)
error('Output directory or extension must be different, refuse to overwrite file "%s', thisfile);
end
img = imread(thisfile);
if ndims(img) > 2
warning('skipping file that is already color: %s', thisfile);
continue;
end
imwrite(img, cmap, outfile);
end
fprintf('Done\n');

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by