tiff - Adding an alpha channel to geoTIFF image in Matlab -


trying add alpha (transparency) channel rgb data in georeferenced tiff image. led through process of creating geotiff in separate question. first part of code creates geotiff attached png file (uk_dt.png), second part creates mask white regions, appends rgb data , attempts modify appropriate tags before rewriting geotiff in new file. resultant image blank. suspect i'm doing wrong 'photometric' tag can't see problem?

file = 'uk_dt.png' ;  [path,name,ext] = fileparts(file) ;  = imread(file) ; = flipud(i);  lonmin = -17; lonmax = 10; latmin = 47; latmax = 63;  % write geotiff r = georasterref('rastersize',size(i),'latitudelimits',[latmin,latmax],'longitudelimits',[lonmin,lonmax]); tiffile = strcat(name,'.tif') ; geotiffwrite(tiffile,i,r) ;  %% have geotiff need transparency.  % make alpha mask identifying white regions s = sum(i,3); mask = 255*ones(size(i,1),size(i,2)); mask(s==765) = 0; % create mask = cat(3,i,mask); % concatenate alpha channel onto rgb data  info = geotiffinfo(tiffile); % reload rgb tiff data  % use tiff tags append alpha data tiffile2 = strcat(name,'2.tif') ; geotiffwrite(tiffile2,i,r,'geokeydirectorytag', ...   info.geotifftags.geokeydirectorytag,'tifftags', ...   struct('extrasamples',tiff.extrasamples.associatedalpha, ...   'photometric',tiff.photometric.separated)); 

edit: having played problem bit more, appears impossible add alpha channel geotiff in matlab (at least without clever workaround) couple of reasons:

1: 'photometric' tag should set 'rgb', colour space we're creating rgb+alpha. there interlock in geotiffwrite prevents writing other x*y*3 array when tag set rgb. code utilised above (found somewhere online) gets round error using 'separated' instead, associated cmyk colour space surely not right setting.

2: set 'extrasamples' tag inform other rgb data expected. in other examples i've seen, have set 'samplesperpixel' tag 4 reflect this. geotiffwrite not recognise valid tag. in fact, diving geotiffwrite code , looking @ tags valid, there fraction of options available compared tiff() command.

i love proved wrong appears i'm going have manually load hundreds of files in external package , change white areas transparent!


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -