Problem bluewhitered function colormap
15 ビュー (過去 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')) )

0 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で White についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
