Is it possible to save a 32bit BMP image (with alpha)
13 次查看(过去 30 天)
显示 更早的评论
Is it possible to save a 32bit BMP image. i.e. image size (imheight x imwidth x 4) where the 4.th channel consist of alpha values?
0 个评论
采纳的回答
Walter Roberson
2011-5-10
imwrite does not support alpha in BMP. See http://www.mathworks.com/matlabcentral/answers/6335-writing-32-bit-images for information on what can be used.
8 个评论
DGM
2024-7-15,5:12
This problem is occurring because imwrite() interprets a 4-channel RGBA image as CMYK (regardless of any asserted colorspace parameter). So anything that decodes the file will likely wind up treating it as CMYK and converting it back into an opaque 24b RGB equivalent.
As far as I know, writing an RGBA TIFF this way isn't an option with imwrite(). It should be possible with the tiff class.
更多回答(1 个)
John
2011-5-12
Here's a demo I did a while back on how to create a TIFF with an alpha layer.
% This image is included with MATLAB
D = imread('street1.jpg');
image(D); title('RGB image without alpha layer.');
h = size(D,1);
w = size(D,2);
% Create a gradually increasing transparency mask
% from left-to-right across the image.
T = zeros(h,w,'uint8');
for j=1:w
T(:,j) = min(255,j) * ones(h,1);
end
% The dimensions of our image are h x w x 3 (remember, it's RGB). If
% we wish to add an alpha component, we need to give the image data a 4th
% component.
rgbaData = cat(3,D,T);
% Let's create our new image.
t = Tiff('alpha.tif','w');
% The photometric interpretation remains RGB, even though we will be
% adding an extra sample.
t.setTag('Photometric',Tiff.Photometric.RGB);
% These three tags define the dimensions of the image in the file.
t.setTag('ImageWidth',w);
t.setTag('ImageLength',h);
t.setTag('BitsPerSample',8);
t.setTag('SamplesPerPixel',4);
% We will make the image consist of 64x64 tiles.
t.setTag('TileWidth',64);
t.setTag('TileLength',64);
t.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
% A photometric interpretation of RGB means that the TIFF file is expecting
% three components. We have to tell it that there will really be four
% components (the alpha layer is the 4th).
t.setTag('ExtraSamples',Tiff.ExtraSamples.UnassociatedAlpha);
t.write(rgbaData);
t.close();
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!