@@ -33,7 +33,7 @@ public StableDiffusionGif(IStableDiffusionService stableDiffusionService)
33
33
/// </summary>
34
34
public async Task RunAsync ( )
35
35
{
36
- var prompt = "Elon Musk " ;
36
+ var prompt = "Iron Man " ;
37
37
var negativePrompt = "" ;
38
38
39
39
var promptOptions = new PromptOptions
@@ -46,10 +46,10 @@ public async Task RunAsync()
46
46
var schedulerOptions = new SchedulerOptions
47
47
{
48
48
SchedulerType = SchedulerType . LCM ,
49
- Seed = 624461087 ,
49
+ // Seed = 624461087,
50
50
GuidanceScale = 1f ,
51
- InferenceSteps = 12 ,
52
- Strength = 0.5f ,
51
+ InferenceSteps = 20 ,
52
+ Strength = 0.35f ,
53
53
} ;
54
54
55
55
// Choose Model
@@ -63,6 +63,7 @@ public async Task RunAsync()
63
63
64
64
var repeatCount = 0 ;
65
65
var frameDelay = 0 ;
66
+ var imageMerge = 0.88f ;
66
67
67
68
using Image < Rgba32 > gifDestination = new ( schedulerOptions . Width , schedulerOptions . Height ) ;
68
69
{
@@ -72,16 +73,37 @@ public async Task RunAsync()
72
73
using ( var gifSource = await Image . LoadAsync ( Path . Combine ( _outputDirectory , "Source.gif" ) ) )
73
74
using ( var frame = gifSource . Frames . CloneFrame ( 0 ) )
74
75
{
76
+ frame . Mutate ( x => x . Resize ( gifDestination . Size ) ) ;
75
77
for ( int i = 0 ; i < gifSource . Frames . Count ; i ++ )
76
78
{
79
+ var newFrame = gifSource . Frames . CloneFrame ( i ) ;
80
+ newFrame . Mutate ( x => x . Resize ( gifDestination . Size ) ) ;
81
+
77
82
// Draw each frame on top of the last to fix issues with compressed gifs
78
- frame . Mutate ( x => x . DrawImage ( gifSource . Frames . CloneFrame ( i ) , 1f ) ) ;
83
+ frame . Mutate ( x => x . DrawImage ( newFrame , 1f ) ) ;
84
+
85
+ var mergedFrame = frame . CloneAs < Rgba32 > ( ) ;
86
+ if ( i > 1 && imageMerge < 1 )
87
+ {
88
+ // Get Previous SD Frame
89
+ var previousFrame = gifDestination . Frames . CloneFrame ( i - 1 ) ;
90
+
91
+ // Set to Grayscale
92
+ previousFrame . Mutate ( x => x . Grayscale ( ) ) ;
93
+
94
+ // Set BG Frame Opacity
95
+ mergedFrame . Mutate ( x => x . Opacity ( imageMerge ) ) ;
96
+
97
+ // Draw Previous SD Frame
98
+ mergedFrame . Mutate ( x => x . DrawImage ( previousFrame , 1f - imageMerge ) ) ;
99
+ }
100
+
79
101
80
102
// Save Debug Output
81
- await frame . SaveAsPngAsync ( Path . Combine ( _outputDirectory , $ "Debug-Frame.png") ) ;
103
+ await mergedFrame . SaveAsPngAsync ( Path . Combine ( _outputDirectory , $ "Debug-Frame.png") ) ;
82
104
83
105
// Set prompt Image, Run Diffusion
84
- promptOptions . InputImage = new InputImage ( frame . CloneAs < Rgba32 > ( ) ) ;
106
+ promptOptions . InputImage = new InputImage ( mergedFrame . CloneAs < Rgba32 > ( ) ) ;
85
107
var result = await _stableDiffusionService . GenerateAsImageAsync ( model , promptOptions , schedulerOptions ) ;
86
108
87
109
// Save Debug Output
0 commit comments