How to add alpha channel to the image and convert that image into png format?
30 次查看(过去 30 天)
显示 更早的评论
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.
采纳的回答
Walter Roberson
2012-12-31
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 个评论
Walter Roberson
2013-1-2
Superimpose? For display purposes?
image(RGBarray, 'AlphaData', TheAlphaData)
goldensona
2013-1-2
编辑:goldensona
2013-1-2
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
2013-1-2
for image editing purpose, use superimposing or painting ,if i use photoshop to change it will destroy pixel value
Walter Roberson
2013-1-2
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.
更多回答(2 个)
Image Analyst
2012-12-31
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 个评论
goldensona
2013-1-2
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
2013-1-2
编辑:Walter Roberson
2018-3-7
MATLAB image functions are mostly not designed to have an alpha channel stored as part of the same image array.
goldensona
2013-1-2
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
2013-1-2
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
2013-1-4
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
2013-1-4
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
2013-1-4
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
2013-1-6
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
2013-1-6
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
2013-1-6
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
2013-1-6
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
2013-1-6
编辑:goldensona
2013-1-6
ok ,for modification of the image , how can i modified the image data, by using photoshop or painting or superimposing
goldensona
2013-1-6
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
2013-1-6
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
2013-1-6
@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
2013-1-6
编辑:goldensona
2013-1-7
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
2013-1-7
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
2013-1-13
编辑:goldensona
2013-1-13
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
2013-1-13
Please show the sequence of steps you used to read the image and change the pixel value and write it out.
goldensona
2013-1-13
编辑:goldensona
2013-1-13
[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
2013-1-13
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
2013-1-13
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
2013-1-13
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
2013-1-13
can you say how to use photo shop to handle the png image file for create alpha channel plane
Image Analyst
2013-1-13
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
2013-1-28
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
2018-3-7
编辑:Jo
2018-3-7
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Language Support 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)