neginver


Nameneginver JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/Flemyng1999/neginver
SummaryA Python project for automatic Negative Film inversion
upload_time2024-05-26 05:51:26
maintainerNone
docs_urlNone
authorflemyng feng
requires_python>=3.9
licenseNone
keywords python negative film windows mac linux
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # neginver

**Read this in other languages: [中文](README.md), [English](README_EN.md), [日本語](README_JP.md).**

国内胶片之风盛行多日。由于不满时下大多店铺扫描与去色罩质量,已经有部分人开始自己尝试胶片翻拍,但是去色罩对于大多数艺术家们来讲就成了一个“难题”或者说是“麻烦事”。尽管[Negative Lab Pro](https://www.negativelabpro.com)确实方便,但是$99.00的价格让我这种穷人望而却步,并且个人不是太欣赏它那过于讨喜的校色思路,于是乎开发了这个简单的负片去色罩小程序,希望也可以帮助到大家!

原图 ⬇️
![raw color negative film](pic/image_info_raw.png "Raw color negative film")
![raw bw negative film](pic/bw_info_raw.png "Raw bw negative film")
去色罩后 ⬇️
![inversed color negative film](pic/image_info_inver.png "Inversed color negative film")
![inversed color negative film](pic/bw_info_inver.png "Inversed bw negative film")

本项目完全基于Python对图片的原始直方图的统计信息去色罩,不带有人为的控制,力求展示底片本应有的**最自然的颜色**!以下是与nlp对比的样片:

Negative Lab Pro⬇️
![Negative Lab Pro samples](pic/nlp.jpg "Negative Lab Pro samples")
Neginver⬇️
![Neginver samples](pic/neginver.jpg "Neginver samples")

这里是样片的 **[原图](pic/raw_sample)**,欢迎大家自行尝试👏

E-mail: <flemyng1999@outlook.com>

## 安装

使用pip安装即可:

```sh
pip install neginver
```

比较懒,目前没有conda。

## 使用

这个项目目前没有开发GUI,所以仍然要求使用者有一定的python基础。

读取Tif文件。这一步基于[tifffile](https://pypi.org/project/tifffile/)读取tif文件为numpy数组:

```python
import tifffile as tiff

img = tiff.imread(tif_path)
```

由于本人习惯于[band, height, wight]的格式,而tiff.imread()读取的是[height, wight, band]的格式,所以需要用numpy简单处理一下:

```python
import numpy as np

img = np.moveaxis(img, 0, -1)
```

然后将本模块引入:

```python
import neginver as ni

img_inversed = ni.negative_inverse(img_raw, film_type='color', mode='default')
```

最后将img_inversed数组保存为无损的tif文件:

```python
img_final = np.moveaxis(img_inversed, 0, -1)
tiff.imwrite('img.tif', img_final)
```

以上是一张图的流程,本人基于M2 Pro的MacBook Pro测试,一张1200w的图片只需要2.5秒。
使用循环可以批处理:

```python
import os
from pathlib import Path
from datetime import datetime

import tifffile as tiff
import numpy as np
import neginver as ni


# Directory path
data_dir = Path('/Users/flemyng/Desktop/Phocus/2024_05_24')
save_dir = Path('/Users/flemyng/Desktop/Film')

# Get all *.tif files in the directory
tif_files = list(data_dir.glob('*.tif'))

# Resort the list of files
tif_files = sorted(tif_files)

# Get now time
current_date = datetime.now()

# Change date to YYYY_MM_DD
folder_name = current_date.strftime('%Y_%m_%d')

# Initialize a new folder
os.makedirs(save_dir / folder_name, exist_ok=True)

for tif_path in tqdm(tif_files):
    img_raw = np.moveaxis(tiff.imread(tif_path), -1, 0)
    img_inversed = ni.negative_inverse(img_raw, film_type='color', mode='default')

    img = np.moveaxis(img_inversed, 0, -1)

    tiff.imwrite(
        save_dir / folder_name / f'{tif_path.stem}.tif',
        img
    )
```

最后,我建议可以在Lightroom里面再调整一下色调曲线,加入自己的艺术偏好。

## negative_inverse()

negative_inverse()函数是本模块的核心函数。关于negative_inverse()函数的参数,以及如何使用如下:

### 输入参数

```python
img: np.ndarray,
film_type: str = 'color', # 'color', 'bw'
mode: str = 'default',
rates: tuple[float] = (1.195, 1.155),
percentile: float = 0.1,
crop_percentage: float = 0.02,
```

### 参数介绍

**img**:是一个形状为 **[3, height, width]** 的numpy数组,包含图片的原始信息。数组的dtype只支持 **uint8** 和 **uint16** ,uint16完全够用了。不支持float,因为负数比较麻烦;

**film_type**:是底片的类型。如果是彩色胶片选'color';黑白胶片选'bw',黑白用'color'也可以;

**mode**:是校色的模式。有'auto', 'default', 'manual'三种选择:默认就是'default';'auto'一般会偏绿偏蓝,你需要自己再调一下曲线(简单把中心往下调一点就可以);'manual'不推荐,这是我自己用的。

**crop_percentage**:是胶片外一圈黑边所占的比例(从0~1)。比如,0.05就是补考虑图片外围5%的范围的信息。

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Flemyng1999/neginver",
    "name": "neginver",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "python, negative, film, windows, mac, linux",
    "author": "flemyng feng",
    "author_email": "flemyng1999@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/0d/7a/d73827893643168fea36a2db1b3fafef4e5b2ccecdd27f83476c1da1f31b/neginver-0.0.7.tar.gz",
    "platform": null,
    "description": "# neginver\n\n**Read this in other languages: [\u4e2d\u6587](README.md), [English](README_EN.md), [\u65e5\u672c\u8a9e](README_JP.md).**\n\n\u56fd\u5185\u80f6\u7247\u4e4b\u98ce\u76db\u884c\u591a\u65e5\u3002\u7531\u4e8e\u4e0d\u6ee1\u65f6\u4e0b\u5927\u591a\u5e97\u94fa\u626b\u63cf\u4e0e\u53bb\u8272\u7f69\u8d28\u91cf\uff0c\u5df2\u7ecf\u6709\u90e8\u5206\u4eba\u5f00\u59cb\u81ea\u5df1\u5c1d\u8bd5\u80f6\u7247\u7ffb\u62cd\uff0c\u4f46\u662f\u53bb\u8272\u7f69\u5bf9\u4e8e\u5927\u591a\u6570\u827a\u672f\u5bb6\u4eec\u6765\u8bb2\u5c31\u6210\u4e86\u4e00\u4e2a\u201c\u96be\u9898\u201d\u6216\u8005\u8bf4\u662f\u201c\u9ebb\u70e6\u4e8b\u201d\u3002\u5c3d\u7ba1[Negative Lab Pro](https://www.negativelabpro.com)\u786e\u5b9e\u65b9\u4fbf\uff0c\u4f46\u662f$99.00\u7684\u4ef7\u683c\u8ba9\u6211\u8fd9\u79cd\u7a77\u4eba\u671b\u800c\u5374\u6b65\uff0c\u5e76\u4e14\u4e2a\u4eba\u4e0d\u662f\u592a\u6b23\u8d4f\u5b83\u90a3\u8fc7\u4e8e\u8ba8\u559c\u7684\u6821\u8272\u601d\u8def\uff0c\u4e8e\u662f\u4e4e\u5f00\u53d1\u4e86\u8fd9\u4e2a\u7b80\u5355\u7684\u8d1f\u7247\u53bb\u8272\u7f69\u5c0f\u7a0b\u5e8f\uff0c\u5e0c\u671b\u4e5f\u53ef\u4ee5\u5e2e\u52a9\u5230\u5927\u5bb6\uff01\n\n\u539f\u56fe \u2b07\ufe0f\n![raw color negative film](pic/image_info_raw.png \"Raw color negative film\")\n![raw bw negative film](pic/bw_info_raw.png \"Raw bw negative film\")\n\u53bb\u8272\u7f69\u540e \u2b07\ufe0f\n![inversed color negative film](pic/image_info_inver.png \"Inversed color negative film\")\n![inversed color negative film](pic/bw_info_inver.png \"Inversed bw negative film\")\n\n\u672c\u9879\u76ee\u5b8c\u5168\u57fa\u4e8ePython\u5bf9\u56fe\u7247\u7684\u539f\u59cb\u76f4\u65b9\u56fe\u7684\u7edf\u8ba1\u4fe1\u606f\u53bb\u8272\u7f69\uff0c\u4e0d\u5e26\u6709\u4eba\u4e3a\u7684\u63a7\u5236\uff0c\u529b\u6c42\u5c55\u793a\u5e95\u7247\u672c\u5e94\u6709\u7684**\u6700\u81ea\u7136\u7684\u989c\u8272**\uff01\u4ee5\u4e0b\u662f\u4e0enlp\u5bf9\u6bd4\u7684\u6837\u7247\uff1a\n\nNegative Lab Pro\u2b07\ufe0f\n![Negative Lab Pro samples](pic/nlp.jpg \"Negative Lab Pro samples\")\nNeginver\u2b07\ufe0f\n![Neginver samples](pic/neginver.jpg \"Neginver samples\")\n\n\u8fd9\u91cc\u662f\u6837\u7247\u7684 **[\u539f\u56fe](pic/raw_sample)**\uff0c\u6b22\u8fce\u5927\u5bb6\u81ea\u884c\u5c1d\u8bd5\ud83d\udc4f\n\nE-mail: <flemyng1999@outlook.com>\n\n## \u5b89\u88c5\n\n\u4f7f\u7528pip\u5b89\u88c5\u5373\u53ef\uff1a\n\n```sh\npip install neginver\n```\n\n\u6bd4\u8f83\u61d2\uff0c\u76ee\u524d\u6ca1\u6709conda\u3002\n\n## \u4f7f\u7528\n\n\u8fd9\u4e2a\u9879\u76ee\u76ee\u524d\u6ca1\u6709\u5f00\u53d1GUI\uff0c\u6240\u4ee5\u4ecd\u7136\u8981\u6c42\u4f7f\u7528\u8005\u6709\u4e00\u5b9a\u7684python\u57fa\u7840\u3002\n\n\u8bfb\u53d6Tif\u6587\u4ef6\u3002\u8fd9\u4e00\u6b65\u57fa\u4e8e[tifffile](https://pypi.org/project/tifffile/)\u8bfb\u53d6tif\u6587\u4ef6\u4e3anumpy\u6570\u7ec4\uff1a\n\n```python\nimport tifffile as tiff\n\nimg = tiff.imread(tif_path)\n```\n\n\u7531\u4e8e\u672c\u4eba\u4e60\u60ef\u4e8e[band, height, wight]\u7684\u683c\u5f0f\uff0c\u800ctiff.imread()\u8bfb\u53d6\u7684\u662f[height, wight, band]\u7684\u683c\u5f0f\uff0c\u6240\u4ee5\u9700\u8981\u7528numpy\u7b80\u5355\u5904\u7406\u4e00\u4e0b\uff1a\n\n```python\nimport numpy as np\n\nimg = np.moveaxis(img, 0, -1)\n```\n\n\u7136\u540e\u5c06\u672c\u6a21\u5757\u5f15\u5165\uff1a\n\n```python\nimport neginver as ni\n\nimg_inversed = ni.negative_inverse(img_raw, film_type='color', mode='default')\n```\n\n\u6700\u540e\u5c06img_inversed\u6570\u7ec4\u4fdd\u5b58\u4e3a\u65e0\u635f\u7684tif\u6587\u4ef6\uff1a\n\n```python\nimg_final = np.moveaxis(img_inversed, 0, -1)\ntiff.imwrite('img.tif', img_final)\n```\n\n\u4ee5\u4e0a\u662f\u4e00\u5f20\u56fe\u7684\u6d41\u7a0b\uff0c\u672c\u4eba\u57fa\u4e8eM2 Pro\u7684MacBook Pro\u6d4b\u8bd5\uff0c\u4e00\u5f201200w\u7684\u56fe\u7247\u53ea\u9700\u89812.5\u79d2\u3002\n\u4f7f\u7528\u5faa\u73af\u53ef\u4ee5\u6279\u5904\u7406\uff1a\n\n```python\nimport os\nfrom pathlib import Path\nfrom datetime import datetime\n\nimport tifffile as tiff\nimport numpy as np\nimport neginver as ni\n\n\n# Directory path\ndata_dir = Path('/Users/flemyng/Desktop/Phocus/2024_05_24')\nsave_dir = Path('/Users/flemyng/Desktop/Film')\n\n# Get all *.tif files in the directory\ntif_files = list(data_dir.glob('*.tif'))\n\n# Resort the list of files\ntif_files = sorted(tif_files)\n\n# Get now time\ncurrent_date = datetime.now()\n\n# Change date to YYYY_MM_DD\nfolder_name = current_date.strftime('%Y_%m_%d')\n\n# Initialize a new folder\nos.makedirs(save_dir / folder_name, exist_ok=True)\n\nfor tif_path in tqdm(tif_files):\n    img_raw = np.moveaxis(tiff.imread(tif_path), -1, 0)\n    img_inversed = ni.negative_inverse(img_raw, film_type='color', mode='default')\n\n    img = np.moveaxis(img_inversed, 0, -1)\n\n    tiff.imwrite(\n        save_dir / folder_name / f'{tif_path.stem}.tif',\n        img\n    )\n```\n\n\u6700\u540e\uff0c\u6211\u5efa\u8bae\u53ef\u4ee5\u5728Lightroom\u91cc\u9762\u518d\u8c03\u6574\u4e00\u4e0b\u8272\u8c03\u66f2\u7ebf\uff0c\u52a0\u5165\u81ea\u5df1\u7684\u827a\u672f\u504f\u597d\u3002\n\n## negative_inverse()\n\nnegative_inverse()\u51fd\u6570\u662f\u672c\u6a21\u5757\u7684\u6838\u5fc3\u51fd\u6570\u3002\u5173\u4e8enegative_inverse()\u51fd\u6570\u7684\u53c2\u6570\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5982\u4e0b\uff1a\n\n### \u8f93\u5165\u53c2\u6570\n\n```python\nimg: np.ndarray,\nfilm_type: str = 'color', # 'color', 'bw'\nmode: str = 'default',\nrates: tuple[float] = (1.195, 1.155),\npercentile: float = 0.1,\ncrop_percentage: float = 0.02,\n```\n\n### \u53c2\u6570\u4ecb\u7ecd\n\n**img**\uff1a\u662f\u4e00\u4e2a\u5f62\u72b6\u4e3a **[3, height, width]** \u7684numpy\u6570\u7ec4\uff0c\u5305\u542b\u56fe\u7247\u7684\u539f\u59cb\u4fe1\u606f\u3002\u6570\u7ec4\u7684dtype\u53ea\u652f\u6301 **uint8** \u548c **uint16** \uff0cuint16\u5b8c\u5168\u591f\u7528\u4e86\u3002\u4e0d\u652f\u6301float\uff0c\u56e0\u4e3a\u8d1f\u6570\u6bd4\u8f83\u9ebb\u70e6\uff1b\n\n**film_type**\uff1a\u662f\u5e95\u7247\u7684\u7c7b\u578b\u3002\u5982\u679c\u662f\u5f69\u8272\u80f6\u7247\u9009'color'\uff1b\u9ed1\u767d\u80f6\u7247\u9009'bw'\uff0c\u9ed1\u767d\u7528'color'\u4e5f\u53ef\u4ee5\uff1b\n\n**mode**\uff1a\u662f\u6821\u8272\u7684\u6a21\u5f0f\u3002\u6709'auto', 'default', 'manual'\u4e09\u79cd\u9009\u62e9\uff1a\u9ed8\u8ba4\u5c31\u662f'default'\uff1b'auto'\u4e00\u822c\u4f1a\u504f\u7eff\u504f\u84dd\uff0c\u4f60\u9700\u8981\u81ea\u5df1\u518d\u8c03\u4e00\u4e0b\u66f2\u7ebf\uff08\u7b80\u5355\u628a\u4e2d\u5fc3\u5f80\u4e0b\u8c03\u4e00\u70b9\u5c31\u53ef\u4ee5\uff09\uff1b'manual'\u4e0d\u63a8\u8350\uff0c\u8fd9\u662f\u6211\u81ea\u5df1\u7528\u7684\u3002\n\n**crop_percentage**\uff1a\u662f\u80f6\u7247\u5916\u4e00\u5708\u9ed1\u8fb9\u6240\u5360\u7684\u6bd4\u4f8b\uff08\u4ece0\uff5e1\uff09\u3002\u6bd4\u5982\uff0c0.05\u5c31\u662f\u8865\u8003\u8651\u56fe\u7247\u5916\u56f45%\u7684\u8303\u56f4\u7684\u4fe1\u606f\u3002\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python project for automatic Negative Film inversion",
    "version": "0.0.7",
    "project_urls": {
        "Homepage": "https://github.com/Flemyng1999/neginver"
    },
    "split_keywords": [
        "python",
        " negative",
        " film",
        " windows",
        " mac",
        " linux"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0d7ad73827893643168fea36a2db1b3fafef4e5b2ccecdd27f83476c1da1f31b",
                "md5": "1c2b5caa5720b8898d2041926fb11ec7",
                "sha256": "e3869f3a9601e5129520ab53d66f831efb061b7a3afedaf9608b653f49244b72"
            },
            "downloads": -1,
            "filename": "neginver-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "1c2b5caa5720b8898d2041926fb11ec7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 11194,
            "upload_time": "2024-05-26T05:51:26",
            "upload_time_iso_8601": "2024-05-26T05:51:26.388638Z",
            "url": "https://files.pythonhosted.org/packages/0d/7a/d73827893643168fea36a2db1b3fafef4e5b2ccecdd27f83476c1da1f31b/neginver-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-26 05:51:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Flemyng1999",
    "github_project": "neginver",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "neginver"
}
        
Elapsed time: 0.40935s