You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to add alpha channel to the image and convert that image into png format?
81 views (last 30 days)
Show older comments
Hi i want to combine image with the alpha channel having 100%opacity no color it. and after some processing i have to remove the aplha channel .how to remove it can anyone help me to do.
Accepted Answer
Walter Roberson
on 31 Dec 2012
imwrite(RGBarray, filename, 'png', 'Alpha', ones(size(RGBarray,1),size(RGBarray,2)) )
When you imread(), use
[RGBdata, map, alpha] = imread(filename, 'png');
Note: this is specific to PNG files. A couple of other image formats handle Alpha this way, but some of the other image formats handle Alpha in other ways.
6 Comments
Walter Roberson
on 2 Jan 2013
Superimpose? For display purposes?
image(RGBarray, 'AlphaData', TheAlphaData)
goldensona
on 2 Jan 2013
Edited: goldensona
on 2 Jan 2013
not for display purpose,i need to change image data to another data ( like if document image having "east" , i want to change it as "west" using superimposing , after some process i have to recover from to east).
goldensona
on 2 Jan 2013
for image editing purpose, use superimposing or painting ,if i use photoshop to change it will destroy pixel value
Walter Roberson
on 2 Jan 2013
If you change the RGB array values of the image, then they are changed just like with photoshop.
You can display one image on top of another, but it does not sound like you want to do that.
More Answers (2)
Image Analyst
on 31 Dec 2012
I'm not sure exactly what you mean. Do you just want to put stuff in the overlay, like with functions plot(), line(), patch(), annotation(), etc. and be able to turn them on or off? Or do you want to save stuff you put in the overlay, say burned into the image and saved as a disk file with export_fig()? Or do you want to do what Walter suggested?
31 Comments
goldensona
on 2 Jan 2013
after added aplha channel i want to embbed origninal image data into it,after that i have to reconstruct the data from alpha channel and check the data.
Walter Roberson
on 2 Jan 2013
Edited: Walter Roberson
on 7 Mar 2018
MATLAB image functions are mostly not designed to have an alpha channel stored as part of the same image array.
goldensona
on 2 Jan 2013
can you tell me why it used, i want to store the original image data using some method, if there is any modification in image it will affect alpha channel or the original image ?
Walter Roberson
on 2 Jan 2013
I do not know why MATLAB Image Processing Toolbox does not support RGBA arrays. It was a design decision. RGBA would complicate tools such as rgb2bw() and rgb2hsv().
"modification in image": are you talking about "brushing"? I doubt you are. The figure tools in MATLAB do not change the original data. For example, if you display an image, and rotate that image using the figure Rotate tool, then it is only the display that is changed, not the array that was copied to the display. If you build tools to allow the user to do things like paint, then you have complete control over which arrays get modified and how many "undo" you support and so on.
If you create an image in MATLAB and write it out in a file format that supports an alpha layer (such as PNG), and you take that file into (say) photoshop and modify it there, then which channels get modified are going to depend upon the program and the tools you use within the program.
Might I suggest that you discuss what you are really trying to do? It sounds like you are either attempting to watermark or do steganography.
goldensona
on 4 Jan 2013
i m going to do authentication of a grayscale document image, ie if an document having signature it will modified be attacker means i was stored original image data in the alpha channel with some calculation the identified by alpha channel.
Image Analyst
on 4 Jan 2013
See section
23.4.6.4 On-Line Signatures, Online Signatures
23.4.6.4.1 Off Line Signature Analysis
23.4.6.4.2 Recognition of the Person from Writing, Identification, Authorship, Writer Identification
23.4.6.4.3 Signature Recognition, Surveys, Analysis, Comparisons
Walter Roberson
on 4 Jan 2013
IA, I don't think that kind of "signature" was meant; I think "digital signature" was meant, a means of authenticating that a file has not been modified since it was sent from the document issuing agent.
goldensona
on 6 Jan 2013
i need to check the entire image not only signature,(secret sharing based method for authentication of grayscale document image). is it possible to add the plain image and check with it.
Walter Roberson
on 6 Jan 2013
add the plain image to what?
If you watermark the image, then what would be the difference between checking the entire image and checking the signature ?
goldensona
on 6 Jan 2013
i want to send image to receiver ,at the sender side add pure alpha channel(png image with 100%opacity) with the image and using secret sharing scheme create authentication signal and embeed shares into the alpha channel. at the receiver side check shares and verify the authentication signals ,if any modification by attacker on that image ,i have to identify and rectify the image. now i want to know is it possible how to combine the pure transparency image with my image. and how to remove from it.
Walter Roberson
on 6 Jan 2013
As discussed before, to combine the pure transparency image with the png image, imwrite() and specify the alphalayer parameter. To remove the alpha layer, imread() without bothering to store the alpha that is returned.
goldensona
on 6 Jan 2013
Edited: goldensona
on 6 Jan 2013
ok ,for modification of the image , how can i modified the image data, by using photoshop or painting or superimposing
goldensona
on 6 Jan 2013
ok can you tell which method is best and easy to recover image, the modification should be on the alpha channel ,if i remove the alpha plane i can easy easily recover.
Walter Roberson
on 6 Jan 2013
I am confused about whether you are planning to modify the original image data and add alpha data, on the sender side, and then on the receiver, recover the original image by examining the combined information, after which you would strip away the alpha leaving just the recovered image?
Or on the sender side are you just adding alpha data to the original image, and then on the receiver side using the alpha data to validate that the original was untouched?
And when you ask about photoshop and so on, are you asking about programs that someone could hypothetically use to modify the combined image, and you are asking us for instructions on using one of them to modify an image so that you can test out that your algorithm correctly detects whether the file was modified or not?
Or are you still asking about how you use MATLAB to write out an image as a PNG file that has alpha data, and how, once you use MATLAB to read in such a PNG file, you can remove the alpha data layer ?
goldensona
on 6 Jan 2013
@walter: sorry for my poor english, or my question was not clear
user A send one document(example: check) to user B, User c modified the content of the document and send to user B. User B authenticate the document and verified the document is send by A if any modification means using some process they have to repaired it . ( i m asked about this paper http://people.cs.nctu.edu.tw/~whtsai/Journal%20Paper%20PDFs/Lee_&_Tsai_IEEETIP_2011.pdf)
For that i take one image added the alpha channel and create the image with the png format ,using shamir secrete sharing scheme i added shares into the alphachannel plane combine with orginal image. now i want to check and authenticate the process. so i need to modify the image in some area . which method is used to modify the image and i have to rectify it.
goldensona
on 6 Jan 2013
Edited: goldensona
on 7 Jan 2013
imwrite(RGBarray, 'alphpla.png', 'png', 'Alpha', ones(size(RGBarray,1),size(RGBarray,2)) )
i have changed the pixel value in 'alphpla.png' and save it as png, while read the image
[RGBdata, map, alpha] = imread('alphpla.png', 'png');
alpha data is null, can any one say why it is. how to edit the pixel value and save alpha png image
Walter Roberson
on 7 Jan 2013
It works fine when I try with rand(64,65) as the data.
As a test, try again, and then try again after that with an alpha that is not all 1's.
goldensona
on 13 Jan 2013
Edited: goldensona
on 13 Jan 2013
i have first write the the alpha channel value and create new file read the take the written image aplhaa1.png and changed the one pixel value and save it as alphaa2.png, now i m try to read the alphaa2.png using [RGBdata, map, alpha] = imread('alphaa2.png', 'png');
it didnt return alpha plane value it return as empty array, if we changed the image with alpha plan image ,we couldn't retrieve the alpha plane ?
Walter Roberson
on 13 Jan 2013
Please show the sequence of steps you used to read the image and change the pixel value and write it out.
goldensona
on 13 Jan 2013
Edited: goldensona
on 13 Jan 2013
[RGBarray map Alpha ] = imread('CanadianCheque.png');%read image
%create alphachannel plane with the image
imwrite(RGBarray, 'alphacanadianchequ.png', 'png', 'Alpha', ones(size(RGBarray,1),size(RGBarray,2)) ) ;
%read the alphachannel image and modified one pixel value
[tampim ] = imread('alphacanadianchequ.png');
tampim(3,4)=255;
%save it as new image
imwrite(tampim,'tamperedalpha.png','png');
display('Tampared image created')
%now again i have read the new modified image ,and try to get alpha channel plane
[RGBdata, map, alpha] = imread('tamperedalpha.png', 'png');
now i have checked the alpha array it display empty array[]
Walter Roberson
on 13 Jan 2013
When you re-read the image you have to read the alpha channel, and you have to write the alpha channel when you re-write.
goldensona
on 13 Jan 2013
is not possible without re-read the alpha value ,change the pixel value? is it possible to paint on the image without affect the alpha value ? paint is used to modified the image.
Walter Roberson
on 13 Jan 2013
The way that MATLAB handles PNG files requires that you read the alpha data with the image and write the alpha data out with the modified image. If you were to use a different program such as Photoshop, it might take care of that detail for you.
goldensona
on 13 Jan 2013
can you say how to use photo shop to handle the png image file for create alpha channel plane
Image Analyst
on 13 Jan 2013
I have Photoshop but I haven't done that, so I'd have to look in the Photoshop help for directions - something you can do as easily as me, so . . . good luck!
Walter Roberson
on 28 Jan 2013
Maybe, if it were defined. But it sounds like something that should be analyzed through theory (which is outside the scope of this forum), or else through experimentation.
Jo
on 7 Mar 2018
Edited: Jo
on 7 Mar 2018
If you need using TIFF format to add alpha channel, you can refer to this page: https://www.mathworks.com/help/matlab/ref/tiff-class.html#btqyn4b-3
The second example can solve your problem:
rgb = imread('example.tif');
numrows = size(rgb,1);
numcols = size(rgb,2);
alpha = 255*ones([numrows numcols], 'uint8');
data = cat(3,rgb,alpha);
t = Tiff('myfile.tif','w');
t.setTag('Photometric',Tiff.Photometric.RGB);
t.setTag('Compression',Tiff.Compression.None);
t.setTag('BitsPerSample',8);
t.setTag('SamplesPerPixel',4);
t.setTag('SampleFormat',Tiff.SampleFormat.UInt);
t.setTag('ExtraSamples',Tiff.ExtraSamples.Unspecified);
t.setTag('ImageLength',numrows);
t.setTag('ImageWidth',numcols);
t.setTag('TileLength',32);
t.setTag('TileWidth',32);
t.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
t.write(data);
t.close();
1 Comment
See Also
Categories
Find more on Language Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)