(p: StableDiffusionProcessing, samples)
| 290 | |
| 291 | |
| 292 | def process_samples(p: StableDiffusionProcessing, samples): |
| 293 | out_images = [] |
| 294 | out_infotexts = [] |
| 295 | if not isinstance(samples, list): |
| 296 | return samples, [] |
| 297 | for i, sample in enumerate(samples): |
| 298 | debug(f'Processing result: index={i+1}/{len(samples)}') |
| 299 | p.batch_index = i |
| 300 | if isinstance(sample, Image.Image) or (isinstance(sample, list) and isinstance(sample[0], Image.Image)): |
| 301 | image = sample |
| 302 | sample = np.array(sample) |
| 303 | else: |
| 304 | sample = validate_sample(sample) |
| 305 | image = Image.fromarray(sample) |
| 306 | |
| 307 | if isinstance(image, list): |
| 308 | if len(image) > 1: |
| 309 | log.warning(f'Processing: images={image} contains multiple images using first one only') |
| 310 | image = image[0] |
| 311 | |
| 312 | if not shared.state.interrupted and not shared.state.skipped: |
| 313 | |
| 314 | if p.detailer_enabled: |
| 315 | p.ops.append('detailer') |
| 316 | if not p.do_not_save_samples and get_opt(p, 'save_images_before_detailer'): |
| 317 | info = create_infotext(p, p.prompts, p.seeds, p.subseeds, index=i) |
| 318 | images.save_image(image, path=p.outpath_samples, basename="", seed=p.seeds[i], prompt=p.prompts[i], extension=get_opt(p, 'samples_format'), info=info, p=p, suffix="-before-detailer") |
| 319 | sample = detailer.detail(sample, p) |
| 320 | if isinstance(sample, list): |
| 321 | if len(sample) > 0: |
| 322 | image = Image.fromarray(sample[0]) |
| 323 | if len(sample) > 1: |
| 324 | annotated = sample[1] if isinstance(sample[1], Image.Image) else Image.fromarray(sample[1]) |
| 325 | out_images.append(annotated) |
| 326 | out_infotexts.append("Detailer annotations") |
| 327 | elif sample is not None: |
| 328 | image = Image.fromarray(sample) |
| 329 | |
| 330 | if p.color_corrections is not None and i < len(p.color_corrections): |
| 331 | p.ops.append('color') |
| 332 | if not p.do_not_save_samples and get_opt(p, 'save_images_before_color_correction'): |
| 333 | image_without_cc = apply_overlay(image, p.paste_to, i, p.overlay_images) |
| 334 | info = create_infotext(p, p.prompts, p.seeds, p.subseeds, index=i) |
| 335 | images.save_image(image_without_cc, path=p.outpath_samples, basename="", seed=p.seeds[i], prompt=p.prompts[i], extension=get_opt(p, 'samples_format'), info=info, p=p, suffix="-before-color-correct") |
| 336 | method = p.color_correction_method if p.color_correction_method is not None else getattr(shared.opts, 'color_correction_method', 'histogram') |
| 337 | image = apply_color_correction(p.color_corrections[i], image, method=method) |
| 338 | |
| 339 | if p.scripts is not None and isinstance(p.scripts, scripts_manager.ScriptRunner): |
| 340 | pp = scripts_manager.PostprocessImageArgs(image) |
| 341 | p.scripts.postprocess_image(p, pp) |
| 342 | if pp.image is not None: |
| 343 | image = pp.image |
| 344 | |
| 345 | grading_params = processing_grading.GradingParams( |
| 346 | brightness=getattr(p, 'grading_brightness', 0.0), |
| 347 | contrast=getattr(p, 'grading_contrast', 0.0), |
| 348 | saturation=getattr(p, 'grading_saturation', 0.0), |
| 349 | hue=getattr(p, 'grading_hue', 0.0), |
no test coverage detected