Instructions to use LinxiaoShi/Magicbokeh with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use LinxiaoShi/Magicbokeh with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("LinxiaoShi/Magicbokeh", dtype=torch.bfloat16, device_map="cuda") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
File size: 1,943 Bytes
a6fc6ea edbc5be 0b5c3c1 edbc5be | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ---
license: mit
base_model:
- Manojb/stable-diffusion-2-1-base
pipeline_tag: image-to-image
library_name: diffusers
---
# Towards Photorealistic and Efficient Bokeh Rendering via Diffusion Framework
This repository contains the model and code for **Towards Photorealistic and Efficient Bokeh Rendering via Diffusion Framework**, as presented in the paper:
[**Towards Photorealistic and Efficient Bokeh Rendering via Diffusion Framework**](https://arxiv.org/abs/2605.07429)
## Abstract
Existing mobile devices are constrained by compact optical designs, such as small apertures, which make it difficult to produce natural, optically realistic bokeh effects. Although recent learning-based methods have shown promising results, they still struggle with photos captured under high digital zoom levels, which often suffer from reduced resolution and loss of fine details. A naive solution is to enhance image quality before applying bokeh rendering, yet this two-stage pipeline reduces efficiency and introduces unnecessary error accumulation. To overcome these limitations, we propose MagicBokeh, a unified diffusion-based framework designed for high-quality and efficient bokeh rendering. Through an alternative training strategy and a focus-aware masked attention mechanism, our method jointly optimizes bokeh rendering and super-resolution, substantially improving both controllability and visual fidelity. Furthermore, we introduce degradation-aware depth module to enable more accurate depth estimation from low-quality inputs. Experimental results demonstrate that MagicBokeh efficiently produces photorealistic bokeh effects, particularly on real-world low-resolution images, paving the way for future advancements in bokeh rendering.
## Code and Usage
The official code and model are available at the following GitHub repository:
[https://github.com/vivoCameraResearch/MagicBokeh](https://github.com/vivoCameraResearch/MagicBokeh) |