Repository navigation
feat(pixel-grid): add independent native grid reconstructor - #495
Conversation
Detected grids need a separate local stage that can rebuild one color per cell. Add deterministic two-stage reconstruction with bounded memory and explicit grid arguments. Images can now be rebuilt without invoking detection, application services, or generation flows.
The native reconstructor needs a reproducible package boundary and dependency graph. Add the Rust manifest, locked dependencies, and local target exclusion. The reconstruction module can now build independently with deterministic inputs.
Explicit reconstruction must preserve source colors without creating dense-grid artifacts. Cover exact cells, uncapped final palettes, bad points, input limits, and working-set rejection. Color and resource regressions now fail before this module reaches the application layer.
The extracted reconstruction algorithm must remain traceable and license compliant. Document its explicit-grid contract, two-stage color behavior, fixed upstream revision, and MIT terms. Maintainers can review the reuse boundary without consulting the generation codebase.
The standalone reconstructor needs a narrow gate independent of backend CI. Run format and locked release tests only for reconstructor paths and its workflow. Reconstruction changes now receive isolated validation without touching generation jobs.
|
Deployment failed for project windup with the following error: Learn More: https://vercel.com/huyan-s-projects1?upgradeToPro=build-rate-limit |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Transparent pixel metadata could tint a cell that reconstructs as opaque. Exclude non-visible pixels from selected and fallback visible color averages. Opaque cell colors now reflect only pixels that contribute visible color.
The visible-color regression needs a fixture with conflicting hidden RGB data. Add a majority-opaque red cell whose transparent pixels store blue channels. The test prevents hidden PNG metadata from tinting reconstructed output.
The reconstructor is a native algorithm library rather than Python backend code. Move the independent crate to the root native area and remove the retired CLI. The later PyO3 binding can consume it without coupling this module to Python.
The reconstructor workflow still watched the retired backend-native path. Point path filters and the working directory at the independent native crate. Reconstruction checks now run for the relocated module.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
@fennoai 介绍下这里的“像素重建”具体算法是什么样的,评估下是否有必要单独使用 rust 实现,使用 python 实现成本是否高 |
分析结论这部分“像素重建”不是检测网格,而是在调用方已经给出 算法流程
对应实现主要在 是否有必要单独用 Rust从算法本身看,不是必须。 Python 完全可以实现:Pillow 负责 PNG/JPEG 解码编码,NumPy 负责数组化的网格映射、投票和加权聚合,k-means 可以自己写或使用 scikit-learn。若只在 Python 后端内部调用、图片规模不大、部署环境已有 NumPy/Pillow,那么 Python 版本的实现成本并不高,核心算法大约是中等复杂度,而不是 Rust 才能完成的算法。 从工程边界看,Rust 有合理价值,但理由主要是交付形态和约束,而非“Python 性能一定不够”:
成本判断与建议
我的判断是:如果目标只是当前 Python 管线里的功能,Python + NumPy 足够,没必要为了算法重写 Rust;如果目标是长期维护的独立原生库、明确的内存边界、可复用 API,以及 #492 的薄 PyO3 集成,那么保留 Rust 是合理的架构选择。 这更像“边界/复用/部署”的投资,而不是当前算法对 Python 的硬性性能要求。 验证
|
|
@huyanxius 看上去没有什么有很强的理由走 rust?考虑到额外引入一种语言增加的开发、维护成本,我建议走服务端原来的 python 实现 |
有开源代码可以复用 |
@xyh202131 是指当前的采样算法本身,还是指依赖的库(image、rayon)? |
好像都有,不需要做什么调整即可复用 |
这个是直接拿图片像素画效果最好的一个库复用的。但因为这个库是rust写的,如果想要使用python实现,迁移这个rust库的成本巨高,估算在五六千行代码。 |
@xiaocheny214 现在来看很低了,之前高是因为detector占了 5000 多行,现在我们把那一套detector弃用了,这里的核心 Rust 源码大概只有 500 多行,我觉得可以按照导师的意思,用 Python 来实现 |
@xiaocheny214 我没在依赖中看到这个库,还是说现在提交的 src 的内容就是这个库?如果是的话,那核心算法应该也有 4、5 百行代码,迁移为 python 需要五六千行很奇怪啊
现在依赖的这俩看上去都是跟这个算法无关的基础能力,python 社区理应有对应的替代,总感觉是哪里我们理解上有偏差 |
指的是采样算法本身。当前两阶段重建和 deterministic k-means 来自 Retro-Diffusion/pixel-art-fixer,image、rayon 只是解码和并行依赖。 |
@nighca 他应该是把之前的代码算进来了🤣目前来看就是 500 行左右 |
|
@nighca 那我先来按 Python 迁移一个版本,然后对比原来的 rust 测试一下质量和速度?这样如何? |
@huyanxius 可以的,其实质量不应该有差异,因为质量是算法决定的,而跨语言迁移理论上不影响算法。 |
xyh202131
left a comment
There was a problem hiding this comment.
独立算法库边界明确,CI 与资源限制覆盖完整;可以合并。
新增与检测器和业务应用解耦的显式网格重建库:调用方给定网格后,Rust 模块返回每格单色的原生 1x PNG;源码位于仓库根目录,不属于 Python 后端。
Why
网格识别与像素重建是两种不同职责。把重建逻辑绑定在检测器、Python 后端或生成管线中,会导致后续替换检测算法时同时改动颜色恢复,并扩大本地算法的业务耦合。
Changes
cols、rows、colors并返回 PNG。colors只控制结构聚类,不硬性截断最终全局色板。native/pixel-perfect/crates/reconstructor/,删除生产 stdin/stdout CLI。Implementation
reconstruct_bytes是唯一算法入口;网格参数是唯一空间契约,模块不推断像素密度。Verification
cargo fmt --check:通过。cargo test --release --locked:8 项测试通过,0 项失败。git diff --check upstream/main...HEAD:通过。Scope
colors不是最终图片颜色数上限,不强制 16 色,也不额外引入黑色。Related Issues
Closes #491
Refs #489