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.
How do I limit the range of a colormap when using imwrite
14 views (last 30 days)
Show older comments
Michael Devereux on 23 Apr 2018
Commented: Michael Devereux on 25 Apr 2018
I want to save an image with imwrite and get the same output as the code below displays on screen
Is it possible to set a caxis property for imwrite?
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.
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);
rhoi2(rhoi2<.55) = .55;
rhoi2(rhoi2> .95) = .95;
Guillaume on 24 Apr 2018
Before the call to ind2rgb (or imwrite), you need to rescale your matrix as colour indices so that the minimum is index 1 (for type double, 0 for type uint8) and maximum is index 256 (255 for uint8):
X = round(1 + (rhoi2 - min(rhoi2(:))) * 255 / (max(rhoi2(:)) - min(rhoi2(:)))); %using double
RGB = ind2rgb(X, cmap);
More Answers (1)
Ahmet Cecen on 23 Apr 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(:));
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!