Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problems with imwrite and TIFF format

Subject: Problems with imwrite and TIFF format

From: Nic Roberts

Date: 13 Apr, 2012 14:28:13

Message: 1 of 3

Hi,
I'm using 'imwrite' to create a new greyscale (int16) TIFF file but when I read the file back in all the image has been binaried (sp?) that is the greyscale values are either 0 or 255 also the int16 values I thought I had written have been converted to uint8.

I'm sure I'm missing something obvious here.

The code:

clear;
for k=1:445 %stack length 445
    num=k-1;
    % Generate input file name
    str_num_in=num2str(num);
    prefix='Image_00';
    if (num<10)
        pad=strcat(prefix,'00');
    elseif (num>9)&&(num<100)
        pad=strcat(prefix,'0');
    elseif (num>99)
        pad=strcat(prefix,'');
    end
    name_in=strcat(pad,str_num_in,'.DCM;1');

    % Read in file crop and threshold
    I=dicomread(name_in);
    Thres_I=zeros(1024,1024);
    for i=1:1024
        for j=1:1024
            if (I(i,j)>2500)&&(sqrt((i-512)^2+(j-512)^2)<500)
                Thres_I(i,j)=I(i,j);
            end
        end
    end

    % Generate output file name and write file
    str_num_out=num2str(num+1);
    name_out=strcat('Thres_',str_num_out,'.tif');
    imwrite(Thres_I,name_out,'TIFF');
end

Subject: Problems with imwrite and TIFF format

From: John

Date: 13 Apr, 2012 18:01:21

Message: 2 of 3

IMWRITE doesn't support writing int16 data. If you have R2009b or more recent, you may use the Tiff class instead.



"Nic Roberts" wrote in message <jm9d5t$hel$1@newscl01ah.mathworks.com>...
> Hi,
> I'm using 'imwrite' to create a new greyscale (int16) TIFF file but when I read the file back in all the image has been binaried (sp?) that is the greyscale values are either 0 or 255 also the int16 values I thought I had written have been converted to uint8.
>
> I'm sure I'm missing something obvious here.
>
> The code:
>
> clear;
> for k=1:445 %stack length 445
> num=k-1;
> % Generate input file name
> str_num_in=num2str(num);
> prefix='Image_00';
> if (num<10)
> pad=strcat(prefix,'00');
> elseif (num>9)&&(num<100)
> pad=strcat(prefix,'0');
> elseif (num>99)
> pad=strcat(prefix,'');
> end
> name_in=strcat(pad,str_num_in,'.DCM;1');
>
> % Read in file crop and threshold
> I=dicomread(name_in);
> Thres_I=zeros(1024,1024);
> for i=1:1024
> for j=1:1024
> if (I(i,j)>2500)&&(sqrt((i-512)^2+(j-512)^2)<500)
> Thres_I(i,j)=I(i,j);
> end
> end
> end
>
> % Generate output file name and write file
> str_num_out=num2str(num+1);
> name_out=strcat('Thres_',str_num_out,'.tif');
> imwrite(Thres_I,name_out,'TIFF');
> end

Subject: Problems with imwrite and TIFF format

From: Nic Roberts

Date: 16 Apr, 2012 09:52:06

Message: 3 of 3

Thanks John, I'm now using uint16 and it works fine.

Nic

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us