|
8 | 8 | using OnnxStack.StableDiffusion.Helpers; |
9 | 9 | using SixLabors.ImageSharp; |
10 | 10 | using SixLabors.ImageSharp.Processing; |
11 | | -using SixLabors.ImageSharp.Processing.Processors.Transforms; |
12 | 11 | using System; |
13 | 12 | using System.Collections.Generic; |
14 | 13 | using System.Linq; |
@@ -91,8 +90,6 @@ public override async Task<DenseTensor<float>> DiffuseAsync(PromptOptions prompt |
91 | 90 |
|
92 | 91 | // Apply mask and combine |
93 | 92 | latents = ApplyMaskedLatents(steplatents, initLatentsProper, maskImage); |
94 | | - |
95 | | - ImageHelpers.TensorToImageDebug(latents, $@"D:\Debug\Latent{step}.png"); |
96 | 93 | } |
97 | 94 |
|
98 | 95 | progress?.Invoke(++step, timesteps.Count); |
@@ -167,9 +164,7 @@ private DenseTensor<float> PrepareMask(PromptOptions promptOptions, SchedulerOpt |
167 | 164 | { |
168 | 165 | var pixelSpan = img.GetRowSpan(y); |
169 | 166 | var value = (float)pixelSpan[x].A / 255.0f; |
170 | | - |
171 | | - //TODO: mask = 1 - mask # repaint white, keep black |
172 | | - maskTensor[0, 0, y, x] = 0f; |
| 167 | + maskTensor[0, 0, y, x] = 1f - value; |
173 | 168 | maskTensor[0, 1, y, x] = 0f; // Needed for shape only |
174 | 169 | maskTensor[0, 2, y, x] = 0f; // Needed for shape only |
175 | 170 | maskTensor[0, 3, y, x] = 0f; // Needed for shape only |
@@ -203,7 +198,7 @@ private DenseTensor<float> ApplyMaskedLatents(DenseTensor<float> latents, DenseT |
203 | 198 | float latentsValue = latents[batch, channel, height, width]; |
204 | 199 | float initLatentsProperValue = initLatentsProper[batch, channel, height, width]; |
205 | 200 |
|
206 | | - //TODO: Apply the logic to compute the result based on the mask |
| 201 | + //Apply the logic to compute the result based on the mask |
207 | 202 | float newValue = (initLatentsProperValue * maskValue) + (latentsValue * (1f - maskValue)); |
208 | 203 | result[batch, channel, height, width] = newValue; |
209 | 204 | } |
|
0 commit comments