Skip to main content
January 22, 2010
Answered

Remove Empty channel

  • January 22, 2010
  • 3 replies
  • 3307 views

Dear all,

Is there any scripting to remove Empty channel from the Channel palette.

This topic has been closed for replies.
Correct answer Paul Riggott

Here is an example for RGB or CMYK documents.

//Only RGB or CMYK documents
main();
function main(){
if(!documents.length) return;
var doc = activeDocument;
var PixCount =doc.width.as('px') * doc.height.as('px');
var CH=[];
var ChCount =0;
if(doc.mode == DocumentMode.RGB) ChCount =3;
if(doc.mode == DocumentMode.CMYK) ChCount =4;
if(ChCount == 0) return;
for(var a = ChCount;a<doc.channels.length;a++){
CH.push(doc.channels.name);
}
for(var a in CH){
doc.channels[CH
].visible=true;
//if (doc.channels[CH
].histogram[0] == PixCount)doc.channels[CH].remove(); //Black Channel
if (doc.channels[CH
].histogram[255] == PixCount)doc.channels[CH].remove();//White Channel
else doc.channels[CH
].visible=false;

}
}

Stephen Marsh
Community Expert
Community Expert
July 11, 2022

The code posted in this topic no longer works. A related topic with working code here:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/check-if-channel-have-pixels-or-not-script-code/td-p/13061347

 

Participant
December 9, 2015

Hi, I work with many spot colors and CMYK in multichannels mode. I would like to delete empty channels from CMYK.

Some artworks have a filling only in C and M, and an additional 8 spot colors - I would remove the Y and K,
and other artworks to fill the CMY and spots - I want to remove then K.

Are rewrite the script goes to work on multichannel mode?

Inspiring
January 22, 2010

Unlike layers, channels can't be empty. They can be all white or all black. If that is what you want to remove then you could check each channel's histogram to see if the first or last element equals the number of pixels in the document.

January 22, 2010

Yes Right.. To delete only white channels at a time is ther any script..

and thanks 4 de reply

Paul Riggott
Paul RiggottCorrect answer
Inspiring
January 23, 2010

Here is an example for RGB or CMYK documents.

//Only RGB or CMYK documents
main();
function main(){
if(!documents.length) return;
var doc = activeDocument;
var PixCount =doc.width.as('px') * doc.height.as('px');
var CH=[];
var ChCount =0;
if(doc.mode == DocumentMode.RGB) ChCount =3;
if(doc.mode == DocumentMode.CMYK) ChCount =4;
if(ChCount == 0) return;
for(var a = ChCount;a<doc.channels.length;a++){
CH.push(doc.channels.name);
}
for(var a in CH){
doc.channels[CH
].visible=true;
//if (doc.channels[CH
].histogram[0] == PixCount)doc.channels[CH].remove(); //Black Channel
if (doc.channels[CH
].histogram[255] == PixCount)doc.channels[CH].remove();//White Channel
else doc.channels[CH
].visible=false;

}
}