Problem bluewhitered function colormap

9 次查看(过去 30 天)
Hello,
I have a problem using the bluewhitered function. I want to create a average image of a sequence (works) and change the colormap to bluewhitered, where I can see all 3 colors. This doesn't work as planed, because the final picture is just red and white. How can I change that?
pwd=uigetdir('Choose folder with pictures');
savepath=uigetdir('SavePath');
savename='averageIm';
cd (pwd)
DirFiles = dir([pwd '/*.tif']);
jpg_average = 0;
for i = 1:numel(DirFiles)
im=double(imread(DirFiles(i).name));
jpg_average = im + jpg_average;
end
average= double(jpg_average/numel(DirFiles));
figure(1);
colormap(bluewhitered(256));
im = imagesc(average);
cd(savepath);
saveas(figure(1), (strcat('Case_',strcat(savename),'.png')) )

采纳的回答

DGM
DGM 2022-6-14
编辑:DGM 2022-6-14
bluewhitered() doesn't work like normal colormap tools. It actually queries the current axes 'clim' property and the map is truncated such that white corresponds to zero -- no matter what the actual data range is. The default axes 'clim' is [0 1], and the data range is [23 250] (all >0), so the entire colormap returned by bluewhitered() is white-red.
This tool is intended to be used with data that's roughly centered around zero. If you're going to try to apply it to data with some arbitrary range, you can try something like this
savepath = './';
savename = 'asdf';
% i'm just going to kludge this to make it run
jpg_average = 0;
for k = 1:10
im=double(imread(sprintf('AT3_1m4_%02d.tif',k)));
jpg_average = im + jpg_average;
end
average = double(jpg_average/10);
caxis([-1 1]) % force symmetric limits
cm = bluewhitered(256); % get a full map
colormap(cm); % use it
im = imagesc(average); % display the image
% save the actual image instead of saving a screenshot of the image.
% specify the path instead of changing the working directory
outpict = im2uint8(mat2gray(average));
outpict = ind2rgb(outpict,cm);
imwrite(outpict,fullfile(savepath,[savename '.png']))
but bear in mind that the center will just correspond to the midpoint of the data range.
  2 个评论
Jonas Neu
Jonas Neu 2022-6-15
It worked. Thank you very much for your help.
DGM
DGM 2022-6-15
If you find that the answer satisfies your question, you can click 'Accept'. That marks the thread accordingly, and helps make it more likely to be found by other readers looking for answers to similar questions.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Red 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by