Adding alpha channel to image in matlab .. important question

조회 수: 12 (최근 30일)
Nawar Alseelawi
Nawar Alseelawi 2014년 8월 4일
답변: Nawar Alseelawi 2014년 8월 6일
I have this code to adding alpha channel to rgb image in matlab but i didnt understand it ,, can any one explain it to me please ? and how can i display the new image and save it for more use ?
-----------------------------------------------------------------------------
% This image is included with MATLAB
D = imread('C:\Users\Nawar\Desktop\lena.jpg');
image(D); title('RGB image without alpha layer.');
h = size(D,1);
w = size(D,2);
% Create a transparency mask
T = 128*ones(h,w,'uint8');
% 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('alpha2.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();
---------------------------------------------------------------

답변 (1개)

Nawar Alseelawi
Nawar Alseelawi 2014년 8월 6일
please answer me

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by