Sepia modes over different channels
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
wip/
|
wip/
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
*.pyc
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class Sepia:
|
|||||||
"max": 1.0,
|
"max": 1.0,
|
||||||
"step": 0.1
|
"step": 0.1
|
||||||
}),
|
}),
|
||||||
|
"mode": (["sepia", "blue-pia", "green-pia"],),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,12 +24,18 @@ class Sepia:
|
|||||||
|
|
||||||
CATEGORY = "postprocessing/Color Adjustments"
|
CATEGORY = "postprocessing/Color Adjustments"
|
||||||
|
|
||||||
def sepia(self, image: torch.Tensor, strength: float):
|
def sepia(self, image: torch.Tensor, strength: float, mode: str = "sepia"):
|
||||||
if strength == 0:
|
if strength == 0:
|
||||||
return (image,)
|
return (image,)
|
||||||
|
|
||||||
sepia_weights = torch.tensor([0.2989, 0.5870, 0.1140]).view(1, 1, 1, 3).to(image.device)
|
sepia_weights = torch.tensor([0.2989, 0.5870, 0.1140]).view(1, 1, 1, 3).to(image.device)
|
||||||
|
|
||||||
|
if mode == "sepia":
|
||||||
sepia_filter = torch.tensor([1.0, 0.8, 0.6]).view(1, 1, 1, 3).to(image.device)
|
sepia_filter = torch.tensor([1.0, 0.8, 0.6]).view(1, 1, 1, 3).to(image.device)
|
||||||
|
elif mode == "blue-pia":
|
||||||
|
sepia_filter = torch.tensor([0.6, 0.8, 1.0]).view(1, 1, 1, 3).to(image.device)
|
||||||
|
elif mode == "green-pia":
|
||||||
|
sepia_filter = torch.tensor([0.6, 1.0, 0.6]).view(1, 1, 1, 3).to(image.device)
|
||||||
|
|
||||||
grayscale = torch.sum(image * sepia_weights, dim=-1, keepdim=True)
|
grayscale = torch.sum(image * sepia_weights, dim=-1, keepdim=True)
|
||||||
sepia = grayscale * sepia_filter
|
sepia = grayscale * sepia_filter
|
||||||
|
|||||||
@@ -999,6 +999,7 @@ class Sepia:
|
|||||||
"max": 1.0,
|
"max": 1.0,
|
||||||
"step": 0.1
|
"step": 0.1
|
||||||
}),
|
}),
|
||||||
|
"mode": (["sepia", "blue-pia", "green-pia"],),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1007,12 +1008,18 @@ class Sepia:
|
|||||||
|
|
||||||
CATEGORY = "postprocessing/Color Adjustments"
|
CATEGORY = "postprocessing/Color Adjustments"
|
||||||
|
|
||||||
def sepia(self, image: torch.Tensor, strength: float):
|
def sepia(self, image: torch.Tensor, strength: float, mode: str = "sepia"):
|
||||||
if strength == 0:
|
if strength == 0:
|
||||||
return (image,)
|
return (image,)
|
||||||
|
|
||||||
sepia_weights = torch.tensor([0.2989, 0.5870, 0.1140]).view(1, 1, 1, 3).to(image.device)
|
sepia_weights = torch.tensor([0.2989, 0.5870, 0.1140]).view(1, 1, 1, 3).to(image.device)
|
||||||
|
|
||||||
|
if mode == "sepia":
|
||||||
sepia_filter = torch.tensor([1.0, 0.8, 0.6]).view(1, 1, 1, 3).to(image.device)
|
sepia_filter = torch.tensor([1.0, 0.8, 0.6]).view(1, 1, 1, 3).to(image.device)
|
||||||
|
elif mode == "blue-pia":
|
||||||
|
sepia_filter = torch.tensor([0.6, 0.8, 1.0]).view(1, 1, 1, 3).to(image.device)
|
||||||
|
elif mode == "green-pia":
|
||||||
|
sepia_filter = torch.tensor([0.6, 1.0, 0.6]).view(1, 1, 1, 3).to(image.device)
|
||||||
|
|
||||||
grayscale = torch.sum(image * sepia_weights, dim=-1, keepdim=True)
|
grayscale = torch.sum(image * sepia_weights, dim=-1, keepdim=True)
|
||||||
sepia = grayscale * sepia_filter
|
sepia = grayscale * sepia_filter
|
||||||
|
|||||||
Reference in New Issue
Block a user