From: Raphael J on
Hi,
I have a problem with saving images. I want to change the color of images to jet and then save the colored images to a new file. With the following script I got the problem, that all new files are empty, guess it is a problem with "imwrite".

Thanks for any help!

mkdir(image_name,'image_color')
for k = 1 : n
%imreading the images
current_NIR_image = imread(fullfile(image_path,image_data(k).name));

%changing color
imshow(current_NIR_image, jet(2^12));
new_filename = fullfile(image_path,'image_color',image_data(k).name);

%saving in the images in a new folder
imwrite(gcf, new_filename, 'tif');
end
From: kinor on
"Raphael J" <raphael.jenski(a)rwth-aachen.de> wrote in message <hvsj8t$oie$1(a)fred.mathworks.com>...
> Hi,
> I have a problem with saving images. I want to change the color of images to jet and then save the colored images to a new file. With the following script I got the problem, that all new files are empty, guess it is a problem with "imwrite".
>
> Thanks for any help!
>
> mkdir(image_name,'image_color')
> for k = 1 : n
> %imreading the images
> current_NIR_image = imread(fullfile(image_path,image_data(k).name));
>
> %changing color
> imshow(current_NIR_image, jet(2^12));
> new_filename = fullfile(image_path,'image_color',image_data(k).name);
>
> %saving in the images in a new folder
> imwrite(gcf, new_filename, 'tif');
> end

HI,

you are right, 'imwrite' cannot save a figure, use 'saveas'

hth
kinor
From: Raphael J on
Thanks for your reply.
I have tried "saveas" earlier. With saveas my image size raises from 160kb to 2.9Mb!!! So I thought "imwrite" could be the solution. Is there another way? Or maybe a solution with "saveas" I don't see?
With saveas I tried:
saveas(new_image, new_filename, 'tif')
From: kinor on
"Raphael J" <raphael.jenski(a)rwth-aachen.de> wrote in message <hvsmfv$l50$1(a)fred.mathworks.com>...
> Thanks for your reply.
> I have tried "saveas" earlier. With saveas my image size raises from 160kb to 2.9Mb!!! So I thought "imwrite" could be the solution. Is there another way? Or maybe a solution with "saveas" I don't see?
> With saveas I tried:
> saveas(new_image, new_filename, 'tif')

Hi Raphael,

i liked to answer before because you display the image and save, so the change in resolution must occur.

i guess you load a monolayer uint8 image?

an example:

I = imread('cameraman.tif');
rgb = ind2rgb(I, colormap('jet'));
newI = uint8(rgb*255);
imshow(newI)

you can save newI with imwrite

hth
kinor
From: us on
"Raphael J" <raphael.jenski(a)rwth-aachen.de> wrote in message <hvsj8t$oie$1(a)fred.mathworks.com>...
> Hi,
> I have a problem with saving images. I want to change the color of images to jet and then save the colored images to a new file. With the following script I got the problem, that all new files are empty, guess it is a problem with "imwrite".
>
> Thanks for any help!
>
> mkdir(image_name,'image_color')
> for k = 1 : n
> %imreading the images
> current_NIR_image = imread(fullfile(image_path,image_data(k).name));
>
> %changing color
> imshow(current_NIR_image, jet(2^12));
> new_filename = fullfile(image_path,'image_color',image_data(k).name);
>
> %saving in the images in a new folder
> imwrite(gcf, new_filename, 'tif');
> end

one of the solutions

fnam='foo.tif'; % <- your file name...
img=rand(32);
imagesc(img);
colormap(pink);
imf=getframe(gca);
imwrite(imf.cdata,fnam,'tif');
imt=imread(fnam);
figure;
image(imt);

us