Created
December 15, 2021 12:43
-
-
Save kwolbachia/fdcbedb732cfa024000c457c3916a642 to your computer and use it in GitHub Desktop.
imagej macro script to invert an image and keep the original colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kevin Terretaz @kWolbachia | |
// highly inspired by Jerome Mutterer script : https://forum.image.sc/t/invert-rgb-image-without-changing-colors/33571/8 | |
macro "inverted overlay" { | |
setBatchMode(1); | |
title = getTitle(); | |
rgbSnapshot(); | |
run("Invert"); | |
run("HSB Stack"); | |
run("Macro...", "code=v=(v+128)%256 slice"); | |
run("RGB Color"); | |
rename(title+"_inv"); | |
setOption("Changes", 0); | |
setBatchMode(0); | |
} | |
//Should create an RGB snapshot of any kind of opened image | |
function rgbSnapshot(){ | |
Stack.getPosition(channel, slice, frame); | |
getDimensions(width, height, channels, slices, frames); | |
if (channels>1) Stack.getDisplayMode(mode); | |
if (bitDepth()==24) run("Duplicate..."," "); | |
else if (channels==1) run("Duplicate...", "title=toClose channels=&channels slices=&slice frames=&frame"); | |
else if (mode!="composite") run("Duplicate...", "title=toClose channels=channel slices=&slice frames=&frame"); | |
else run("Duplicate...", "duplicate title=toClose slices=&slice frames=&frame"); | |
run("RGB Color", "keep"); | |
rename("snap"); | |
close("toClose"); | |
setOption("Changes", 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment