How do I limit the range of a colormap when using imwrite
Mostrar comentarios más antiguos
I want to save an image with imwrite and get the same output as the code below displays on screen
figure,imagesc(rhoi),
colormap(jet)
caxis([.45*min(rhoi(:)) 0*.55*max(rhoi(:))])
Is it possible to set a caxis property for imwrite?
imwrite(rhoi,jet,'out.png')
EDIT: I have included the full code. Basically, I want the last image RGB to look the same as that displayed by imagesc at each stage.
clear all
close all
clc
Inner = 0; % inner radius of the colour ring
rOuter = 150; % outer radius of the colour ring
[x, y] = meshgrid(-rOuter:.1:rOuter);
[theta, rho] = cart2pol(x, y);
rhoi=imcomplement(rho);
cmap=jet(256);
rhoi2=rhoi;
rhoi2=(rhoi2-min(rhoi2(:)))/(max(rhoi2(:))-min(rhoi2(:)));
figure;imagesc(rhoi2),colormap(cmap);
caxis([.55 .95])
rhoi2(rhoi2<.55) = .55;
rhoi2(rhoi2> .95) = .95;
figure,imagesc(rhoi2)
colormap( cmap);
X=uint8(256*rhoi2);
figure;imagesc(X),colormap( cmap);
RGB=ind2rgb(X,cmap);
figure;imshow(RGB)
3 comentarios
Guillaume
el 24 de Abr. de 2018
Can you confirm that your rhoi matrix is made of positive integers only. Otherwise, attempting to write an indexed image as per your imwrite call makes no sense.
Michael Devereux
el 24 de Abr. de 2018
Michael Devereux
el 24 de Abr. de 2018
Respuesta aceptada
Más respuestas (1)
Ahmet Cecen
el 23 de Abr. de 2018
You should get the same effect if you just did:
rhoi(rhoi<.45*min(rhoi(:))) = .45*min(rhoi(:));
rhoi(rhoi> 0.55*max(rhoi(:)) = 0.55*max(rhoi(:));
1 comentario
Michael Devereux
el 24 de Abr. de 2018
Categorías
Más información sobre Blue en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!