Save image as tif by using imwrite

  • Follow


I thought it is very simple but I'm really stuck.

I want to save in TIF format the image edited by user in GUI. I have the original data array (double), the limit vector clim, and the colormap cmap. I'm working with grayscale now, but the type and color intensities is defined by user. So, very simple:

I=mat2gray(dataArray,[clim(1) clim(2)]);
X=gray2ind(I,256);
image = ind2rgb(X,cmap); or  image = ind2gray(X,cmap); 
imwrite(image,'xxx.tif');

It works, but except the map, and the changing 3+4 on imwrite(X,cmap,'xxx.tif') does not help too (and I have know idea why).

I want that the tif image looks exactly like
imshow(dataArray,[clim(1) clim(2)],'Colormap',cmap);

Could someone help me? 
Thank you.
0
Reply Elena 5/20/2010 10:28:05 PM

On Thu, 20 May 2010 18:28:05 -0400, Elena  <e.e.belova@gmail.com> wrote:

> I thought it is very simple but I'm really stuck.
>
> I want to save in TIF format the image edited by user in GUI. I have the  
> original data array (double), the limit vector clim, and the colormap  
> cmap. I'm working with grayscale now, but the type and color intensities  
> is defined by user. So, very simple:
>
> I=mat2gray(dataArray,[clim(1) clim(2)]);
> X=gray2ind(I,256);
> image = ind2rgb(X,cmap); or  image = ind2gray(X,cmap);  
> imwrite(image,'xxx.tif');
>
> It works, but except the map, and the changing 3+4 on  
> imwrite(X,cmap,'xxx.tif') does not help too (and I have know idea why).
>
> I want that the tif image looks exactly like
> imshow(dataArray,[clim(1) clim(2)],'Colormap',cmap);
>
> Could someone help me? Thank you.


This?

dataArray=magic(50);
clim=[ 1000 3000];
cmap=jet;
imshow(dataArray,[clim(1) clim(2)],'Colormap',cmap);


%I ranges from 0 - 1
I=mat2gray(dataArray,[clim(1) clim(2)]);

%Convert I to indices into the colormap,
%i.e map 0 -1 to 1 - size of colormap
IndI = round(I*size(cmap,1));

imwrite(IndI,cmap,'xxx.tif');
figure; imshow('xxx.tif');
0
Reply Ashish 5/21/2010 1:19:52 PM


On Fri, 21 May 2010 09:19:52 -0400, Ashish Uthama  
<first.last@mathworks.com> wrote:

> On Thu, 20 May 2010 18:28:05 -0400, Elena  <e.e.belova@gmail.com> wrote:
>
>> I thought it is very simple but I'm really stuck.
>>
>> I want to save in TIF format the image edited by user in GUI. I have  
>> the original data array (double), the limit vector clim, and the  
>> colormap cmap. I'm working with grayscale now, but the type and color  
>> intensities is defined by user. So, very simple:
>>
>> I=mat2gray(dataArray,[clim(1) clim(2)]);
>> X=gray2ind(I,256);
>> image = ind2rgb(X,cmap); or  image = ind2gray(X,cmap);  
>> imwrite(image,'xxx.tif');
>>
>> It works, but except the map, and the changing 3+4 on  
>> imwrite(X,cmap,'xxx.tif') does not help too (and I have know idea why).
>>
>> I want that the tif image looks exactly like
>> imshow(dataArray,[clim(1) clim(2)],'Colormap',cmap);
>>
>> Could someone help me? Thank you.
>
>
> This?
>
> dataArray=magic(50);
> clim=[ 1000 3000];
> cmap=jet;
> imshow(dataArray,[clim(1) clim(2)],'Colormap',cmap);
>
>
> %I ranges from 0 - 1
> I=mat2gray(dataArray,[clim(1) clim(2)]);
>
> %Convert I to indices into the colormap,
> %i.e map 0 -1 to 1 - size of colormap
> IndI = round(I*size(cmap,1));
>
> imwrite(IndI,cmap,'xxx.tif');
> figure; imshow('xxx.tif');

Replace ROUND with CEIL. (Round will result in the range 0 to size of  
colormap)
0
Reply Ashish 5/21/2010 1:21:43 PM

Thanks. It works.
0
Reply Elena 5/21/2010 6:27:22 PM

3 Replies
1715 Views

(page loaded in 0.169 seconds)

Similiar Articles:













7/21/2012 7:45:13 PM


Reply: