2012-12-01 89 views
4

我必須處理大量的圖像,並將結果保存到Matlab中具有透明度的圖像文件中。但PNG壓縮需要我太多時間。如何保存沒有壓縮的PNG或具有透明度的TIFF?有沒有其他方法可以保存圖像而不需要壓縮和透明度?Matlab:如何保存TIFF與透明或PNG沒有壓縮?

這是我的第一個問題,對於我錯誤的英語和錯誤的問題風格抱歉,如果有任何問題。

+0

「壓縮太長我。」這是什麼意思?你是否意味着需要太多時間? – leonbloy

+0

@leonboy是的,這意味着「花費太多時間」,當然,謝謝(固定) –

回答

4

使用TIFF類在Matlab你可以寫與transparancy TIFF格式:

%# create a synthetic RGBA image 
ch = checkerboard(100); 
rgba = repmat(ch,[1,1,4]); 
rgba(:,:,4) = rgba(:,:,4)==0; 
rgba = uint8(round(rgba*255)); 

%# create a tiff object 
tob = Tiff('test.tif','w'); 

%# you need to set Photometric before Compression 
tob.setTag('Photometric',Tiff.Photometric.RGB) 
tob.setTag('Compression',Tiff.Compression.None) 

%# tell the program that channel 4 is alpha 
tob.setTag('ExtraSamples',Tiff.ExtraSamples.AssociatedAlpha) 

%# set additional tags (you may want to use the structure 
%# version of this for convenience) 
tob.setTag('ImageLength',size(ch,1)); 
tob.setTag('ImageWidth',size(ch,2)); 
tob.setTag('BitsPerSample',8); 
tob.setTag('RowsPerStrip',16); 
tob.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky); 
tob.setTag('Software','MATLAB') 
tob.setTag('SamplesPerPixel',4); 

%# write and close the file 
tob.write(rgba) 
tob.close 

%# open in Photoshop - see transparency! 
0

「有PNG的沒有未壓縮的變體,它是可以通過僅使用未壓縮的放氣塊來存儲未壓縮數據」

未壓縮DEFLATE塊使用的5個字節+高達65535個字節每未壓縮數據的報頭塊。

http://www.w3.org/TR/PNG-Rationale.html

1

Matlab的imwrite沒有對PNG壓縮級別參數。如果確實如此,則可以將其設置爲零來進行不壓縮。雖然對於TIFF,它確實有none選項Compression,沒有alpha通道。您可以使用Alpha通道編寫舊的Raster(RAS)格式並且不進行壓縮。雖然沒有東西可能會讀取它。

+0

使用TIFF類(但不使用imwrite,顯然),你可以指定有一個alpha通道。 – Jonas