@@ -33,7 +33,7 @@ public StableDiffusionGif(IStableDiffusionService stableDiffusionService)
3333 /// </summary>
3434 public async Task RunAsync ( )
3535 {
36- var prompt = "Elon Musk " ;
36+ var prompt = "Iron Man " ;
3737 var negativePrompt = "" ;
3838
3939 var promptOptions = new PromptOptions
@@ -46,10 +46,10 @@ public async Task RunAsync()
4646 var schedulerOptions = new SchedulerOptions
4747 {
4848 SchedulerType = SchedulerType . LCM ,
49- Seed = 624461087 ,
49+ // Seed = 624461087,
5050 GuidanceScale = 1f ,
51- InferenceSteps = 12 ,
52- Strength = 0.5f ,
51+ InferenceSteps = 20 ,
52+ Strength = 0.35f ,
5353 } ;
5454
5555 // Choose Model
@@ -63,6 +63,7 @@ public async Task RunAsync()
6363
6464 var repeatCount = 0 ;
6565 var frameDelay = 0 ;
66+ var imageMerge = 0.88f ;
6667
6768 using Image < Rgba32 > gifDestination = new ( schedulerOptions . Width , schedulerOptions . Height ) ;
6869 {
@@ -72,16 +73,37 @@ public async Task RunAsync()
7273 using ( var gifSource = await Image . LoadAsync ( Path . Combine ( _outputDirectory , "Source.gif" ) ) )
7374 using ( var frame = gifSource . Frames . CloneFrame ( 0 ) )
7475 {
76+ frame . Mutate ( x => x . Resize ( gifDestination . Size ) ) ;
7577 for ( int i = 0 ; i < gifSource . Frames . Count ; i ++ )
7678 {
79+ var newFrame = gifSource . Frames . CloneFrame ( i ) ;
80+ newFrame . Mutate ( x => x . Resize ( gifDestination . Size ) ) ;
81+
7782 // 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+
79101
80102 // Save Debug Output
81- await frame . SaveAsPngAsync ( Path . Combine ( _outputDirectory , $ "Debug-Frame.png") ) ;
103+ await mergedFrame . SaveAsPngAsync ( Path . Combine ( _outputDirectory , $ "Debug-Frame.png") ) ;
82104
83105 // Set prompt Image, Run Diffusion
84- promptOptions . InputImage = new InputImage ( frame . CloneAs < Rgba32 > ( ) ) ;
106+ promptOptions . InputImage = new InputImage ( mergedFrame . CloneAs < Rgba32 > ( ) ) ;
85107 var result = await _stableDiffusionService . GenerateAsImageAsync ( model , promptOptions , schedulerOptions ) ;
86108
87109 // Save Debug Output
0 commit comments