Wish: extract mask channel of PNG

Ideas for improvements and requests for new features in XnView Classic

Moderators: XnTriq, xnview

Micha
Posts: 129
Joined: Thu Feb 08, 2007 12:51 pm

Wish: extract mask channel of PNG

Post by Micha »

Hello,

it could be nice if XnView would allow to extract the alpha channel from a PNG. I don't know any software that allow to get access to the PNG alpha channel and to save it to a separate file.

Regards,
Micha
User avatar
XnTriq
Moderator & Librarian
Posts: 5663
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Wish: extract mask channel of PNG

Post by XnTriq »

Hi Micha :)
XnTriq ([url=http://newsgroup.xnview.com/viewtopic.php?p=65288#p65288]Channel displays[/url]) wrote:View mode: Image » Extract channel » Red / Green / Blue / Alpha
Micha
Posts: 129
Joined: Thu Feb 08, 2007 12:51 pm

Re: Wish: extract mask channel of PNG

Post by Micha »

Great - thank you for the hints. :)

An other request - often I need the same batch conversation several times a day (convert to RGB or now extract alpha) and switch it on again and again. It could be nice to get a general batch option like "use options next time again".

-Micha
User avatar
XnTriq
Moderator & Librarian
Posts: 5663
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Wish: extract mask channel of PNG

Post by XnTriq »

I believe there are three options:
  1. XnView + .XBS script
  2. XnConvert + .XBS script
  3. NConvert + .BAT/.CMD file
Unfortunately XnView and XnConvert are crashing on me when I try to run this task, and I don't know the correct command-line options for NConvert. :?

We'll need some help from marsh or oops66 for this.
:mrgreen: Gentlemen?
User avatar
oops66
XnThusiast
Posts: 2002
Joined: Tue Jul 17, 2007 1:17 am
Location: France

Re: Wish: extract mask channel of PNG

Post by oops66 »

XnTriq wrote:I believe there are three options:
  1. XnView + .XBS script
  2. XnConvert + .XBS script
  3. NConvert + .BAT/.CMD file
...
Hello,
about the first solution: XnView + .XBS script
Under Xnview v1.96, you can create your own .xbf batch processing files by doing this:

1-) Select or tag your desired images
2-) ( Ctrl+U ) keys to open the batch processing menu
3-) -> into general tab, you can customize the output directory, format, options... ( for example, output directory=test, format=jpg with customized options quality=75%, keep exif=yes, ovewride=rename, keep subfolder structure=yes,... ...and so...)
-> into Transformations tab: \images\extract channel for example\ Add> and select your desired channel to extract (Alpha,or red,or green,or blue), -> then clique "Save" and give a name to your custom .xbf file (example extract_alpha.xbf).
Do the same steeps for extracting the others channels (if desired), and give an other name extract_blue.xbf, ...

The next time, you just should have to select the right .xbf script (mouse select or load...) to do automatically the appropriate job.
XnViewMP Linux X64 - Debian - X64
User avatar
XnTriq
Moderator & Librarian
Posts: 5663
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Wish: extract mask channel of PNG

Post by XnTriq »

Merci, oops66 :D

I had tried that solution, but both XnView and XnConvert are crashing when I start the script:
extract_alpha_channel.xbs wrote:

Code: Select all

extract( 3 )
settings( 3 0 0 0 0 0 )
output_path( X:\Test\Processed\ )
output( png 0 9 )
Exporting the script to extract_alpha_channel.bat produces this:

Code: Select all

nconvert -npcd 2 -size 256x256+0 -ctype grey -corder inter -out png -o X:\Test\Processed\%%.png -extract "X:\Test\Original\rgba.png"
NCONVERT 5.30 gives me an error message:

Code: Select all

C:\PROGRA~1\XnView\1960>nconvert -npcd 2 -size 256x256+0 -ctype grey -corder inter -out png -o X:\Test\Processed\%%.png -extract "X:\Test\Original\rgba.png"

Bad argument -'extract'


C:\PROGRA~1\XnView\1960>
Do we really need the npcd, size & corder switches for extracting a channel?
User avatar
oops66
XnThusiast
Posts: 2002
Joined: Tue Jul 17, 2007 1:17 am
Location: France

Re: Wish: extract mask channel of PNG

Post by oops66 »

XnTriq wrote:...
I had tried that solution, but both XnView and XnConvert are crashing when I start the script:
extract_alpha_channel.xbs wrote:

Code: Select all

extract( 3 )
settings( 3 0 0 0 0 0 )
output_path( X:\Test\Processed\ )
output( png 0 9 )
Right XnTriq, I have a crash too with this script (extract channel) under V1.96 and Wine, probably a bug.
(But I don't know if this bug is present under Windows XP or Vista ? )

I have this message:
wine: Unhandled page fault on write access to 0x00000020 at address 0x6b2d20 (thread 003b), starting debugger...
...And into nconvert 5.30: Bad argument -'extract' too here.

FI, this argument is missing into the nconvert v5.30 help version too:
nconvert.exe -help > nconvert-help.txt
XnViewMP Linux X64 - Debian - X64
Micha
Posts: 129
Joined: Thu Feb 08, 2007 12:51 pm

Re: Wish: extract mask channel of PNG

Post by Micha »

Thank you for all the hints, especially the detailed descriptions. The script solutions are a workaround, but it could be nice to get a easier solution. Why not do it like at Photoshop - additional pressing the ALT-Key makes that the last used settings are used. In this case it would be ALT+Ctrl+U and anything would be fine. Could it be possible to get this feature please? :wink:
User avatar
XnTriq
Moderator & Librarian
Posts: 5663
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Wish: extract mask channel of PNG

Post by XnTriq »

Good news 8)
xnview ([url=http://newsgroup.xnview.com/viewtopic.php?p=74048#p74048]Batch-extraction of alpha channel[/url]) wrote:
XnTriq wrote:What is the syntax for extracting the alpha channel from a 32-bit PNG image and saving the mask as a greyscale PNG?
Currently no way, but i'll add it
User avatar
Drahken
Posts: 884
Joined: Sun Apr 10, 2005 4:29 pm

Re: Wish: extract mask channel of PNG

Post by Drahken »

Xnview can extract the alpha channel/mask, huh? I never knew.
I use image analyzer to extract the masks. When you open a png with alpha transparency in imageanalyzer, it asks if you want to merge the mask. If you choose not to, then it open the image (minus the mask) and the mask as 2 seperate images.
Oh the feuhrer, oh the feuhrer, oh the feuhrer's nipples bonk!
User avatar
oops66
XnThusiast
Posts: 2002
Joined: Tue Jul 17, 2007 1:17 am
Location: France

Re: Wish: extract mask channel of PNG

Post by oops66 »

The extract_alpha_channel.xbs script works now for me under this new 1.96.1 version.
Thanks Pierre.
XnViewMP Linux X64 - Debian - X64
Bitben
Posts: 3
Joined: Tue Sep 15, 2009 7:43 pm
Location: Lille, France

Re: Wish: extract mask channel of PNG

Post by Bitben »

For me, this script produce a gray version of my image, not the mask.
i use the latest vesion.
désolé :?
User avatar
oops66
XnThusiast
Posts: 2002
Joined: Tue Jul 17, 2007 1:17 am
Location: France

Re: Wish: extract alpha channel of PNG

Post by oops66 »

Bitben wrote:For me, this script produce a gray version of my image, not the mask.
i use the latest vesion.
désolé :?
It's normal for the alpha channel into a .png file: black is 100% transparent, white is 0% transparent (opacity=100%), gray is between 0% and 100%
XnViewMP Linux X64 - Debian - X64
Bitben
Posts: 3
Joined: Tue Sep 15, 2009 7:43 pm
Location: Lille, France

Re: Wish: extract mask channel of PNG

Post by Bitben »

yes, i know, but my image come from 3DS and the Alpha cannel is the outline of this object (a mask). and my result image is like a RGB to grayscale transformation in photoshop.

en français, c'est bien aussi, si je ne me fait pas remonter les bretelles par l'e modérateur :
je sais bien ce qu'est un canal alpha mais mon jpeg résultant n'est pas le masque attendu mais une version en niveau de gris de mon image.
Bitben
Posts: 3
Joined: Tue Sep 15, 2009 7:43 pm
Location: Lille, France

Re: Wish: extract mask channel of PNG

Post by Bitben »

am i the only one with this problem?
i tried png converted by xnview (in case of 3DS implementation of PNG were non standard), i see the mask (Preview/ShowMask) but i cant extract it!
i have a grayscale image, ok, but this is not the mask, it's the source image...without colors...
Post Reply