no message

master
mingzailao 2023-09-27 14:05:51 +08:00
commit 85b3a4b5b7
18 changed files with 566 additions and 0 deletions

6
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"recommendations": [
"ms-python.python",
"tabbyml.vscode-tabby"
]
}

24
README.md Normal file
View File

@ -0,0 +1,24 @@
# run
bash run.sh
# 参数
compare1 DICM
compare2 LIME
...
改动的只有image_fileour_method
挑选出感觉还不错的图片之后调整crops
代表的是两个框,[左上角,右下角,宽度,长度,缩放比例]其中缩放比例可以视情况而定暂时都为5
改完了运行即可,觉得合适了就下载下来
any problem

17
config/compare1_1.yaml Normal file
View File

@ -0,0 +1,17 @@
data_root: ./data # 这个不用动
dataset_type: DICM # 这个是在不同的数据集上
ours_method: bezierdce-9 # 这个是我们选取的比较模型
image_file_1: 01.jpg # 这个是图片的文件名
crops_1: [[500,100,100,100,5],[200,200,100,100,5]] # 这是选取的框框
image_file_2: 02.jpg # 这个是图片的文件名
crops_2: [[150,300,100,100,5],[300,500,200,200,5]] # 这是选取的框框
image_file_3: 32.jpg # 这个是图片的文件名
crops_3: [[220,300,100,100,5],[200,600,100,100,10]] # 这是选取的框框
width_cm: 40 # 图片宽度设置
output_image: ./result/compare1_1.pdf # 这个是输出的图片

22
config/compare2_1.yaml Normal file
View File

@ -0,0 +1,22 @@
data_root: ./data # 这个不用动
dataset_type: LIME # 这个是在不同的数据集上
ours_method: bezierdce-5 # 这个是我们选取的比较模型
ours_method_1: bezierdce-10
image_file_1: 7.bmp # 这个是图片的文件名
crops_1: [[200,50,100,100,5],[250,250,200,200,5]] # 这是选取的框框
ours_method_2: bezierdce-5
image_file_2: 5.bmp # 这个是图片的文件名
crops_2: [[500,200,200,200,5],[800,800,400,400,5]] # 这是选取的框框
ours_method_3: bezierdce-5
image_file_3: 3.bmp # 这个是图片的文件名
crops_3: [[220,100,100,100,5],[170,300,100,100,5]] # 这是选取的框框
width_cm: 40 # 图片宽度设置
# 目前不能直接生成pdf主要因为我电脑上面没有latex 正在安装安装完后就可以直接查看pdf 了,然后下载下来放进去,
# 目前可以通过下载html 文件到本地然后查看
output_image: ./result/compare2_1.pdf # 这个是输出的图片

20
config/compare3_1.yaml Normal file
View File

@ -0,0 +1,20 @@
data_root: ./data # 这个不用动
dataset_type: MEF # 这个是在不同的数据集上
ours_method: bezierdce-22 # 这个是我们选取的比较模型
image_file_1: Landscape.png # 这个是图片的文件名
crops_1: [[100,0,100,100,5],[200,200,100,100,5]] # 这是选取的框框
image_file_2: Candle.png # 这个是图片的文件名
crops_2: [[50,50,100,100,5],[120,200,100,100,5]] # 这是选取的框框
image_file_3: Memorial.png # 这个是图片的文件名
crops_3: [[50,50,100,100,5],[200,200,100,100,5]] # 这是选取的框框
width_cm: 40 # 图片宽度设置
# 目前不能直接生成pdf主要因为我电脑上面没有latex 正在安装安装完后就可以直接查看pdf 了,然后下载下来放进去,
# 目前可以通过下载html 文件到本地然后查看
output_image: ./result/compare3_1.pdf # 这个是输出的图片

24
config/compare4_1.yaml Normal file
View File

@ -0,0 +1,24 @@
data_root: ./data # 这个不用动
dataset_type: NPE # 这个是在不同的数据集上
ours_method: bezierdce-22 # 这个是我们选取的比较模型
image_file_1: rail.png # 这个是图片的文件名
crops_1: [[50,0,100,100,5],[200,200,100,100,5]] # 这是选取的框框
image_file_2: harbor.png # 这个是图片的文件名
crops_2: [[0,0,100,100,5],[200,200,100,100,5]] # 这是选取的框框
image_file_3: night fall.png # 这个是图片的文件名
crops_3: [[350,0,100,100,5],[100,100,200,200,5]] # 这是选取的框框
width_cm: 40 # 图片宽度设置
# 目前不能直接生成pdf主要因为我电脑上面没有latex 正在安装安装完后就可以直接查看pdf 了,然后下载下来放进去,
# 目前可以通过下载html 文件到本地然后查看
output_image: ./result/compare4_1.pdf # 这个是输出的图片

26
config/compare5_1.yaml Normal file
View File

@ -0,0 +1,26 @@
data_root: ./data # 这个不用动
dataset_type: VV # 这个是在不同的数据集上
ours_method: bezierdce-22 # 这个是我们选取的比较模型
image_file_1: P1020044.jpg # 这个是图片的文件名
crops_1: [[700,500,200,200,5],[800,800,400,400,5]] # 这是选取的框框
ours_method_2: bezierdce-22
image_file_2: P1000333.jpg # 这个是图片的文件名
crops_2: [[0,400,600,600,5],[600,1200,400,400,5]] # 这是选取的框框
image_file_3: P1000511.jpg # 这个是图片的文件名
crops_3: [[0,0,400,400,5],[800,800,400,400,5]] # 这是选取的框框
width_cm: 40 # 图片宽度设置
# 目前不能直接生成pdf主要因为我电脑上面没有latex 正在安装安装完后就可以直接查看pdf 了,然后下载下来放进去,
# 目前可以通过下载html 文件到本地然后查看
output_image: ./result/compare5_1.pdf # 这个是输出的图片

1
data Symbolic link
View File

@ -0,0 +1 @@
/data/compare

247
main.py Normal file
View File

@ -0,0 +1,247 @@
import simpleimageio as sio
import figuregen
from figuregen.util.templates import FullSizeWithCrops
from figuregen.util.image import Cropbox
import os
import argparse
import yaml
import numpy as np
class MyCrops(FullSizeWithCrops):
def __init__(self, reference_image, method_images, crops,
crops_below = True, method_names = None, use_latex = False,add=False):
""" Shows a reference image next to a grid of crops from different methods.
Args:
reference_image: a reference image (or any other image to put full-size in the lefthand grid)
method_images: list of images, each corresponds to a new column in the crop grid
crops: list of crops to take from each method, each creates a new row and a marker on the reference
crops_below: [optional] if False, the crops will be a column to the right of each image
method_names: [optional] list of string, names for the reference and each method, to put above the crops
use_latex: set to true to pretty-print captions with LaTeX commands (requires TikZ backend)
Returns:
A list of two grids:
The first is a single image (reference), the second a series of crops, one or more for each method.
"""
self._reference_image = reference_image
self._method_images = method_images
self.use_latex = use_latex
self._crops_below = crops_below
self._errors = [
self.compute_error(reference_image, m)
for m in method_images
]
self._crop_errors = [
[
self.compute_error(crop.crop(reference_image), crop.crop(m))
for m in method_images
]
for crop in crops
]
# Put in one list to make our life easier in the following
images = [reference_image]
images.extend(method_images)
# Create the grid for the reference image
self._ref_grid = [ figuregen.Grid(1, 1) for _ in range(len(images)) ]
for i in range(len(images)):
self._ref_grid[i][0, 0].image = self.tonemap(images[i])
for crop in crops:
self._ref_grid[i][0, 0].set_marker(crop.marker_pos, crop.marker_size, color=[255,255,255])
# Create the grid with the crops
if self._crops_below:
self._crop_grid = [
figuregen.Grid(num_cols=len(crops), num_rows=1)
for _ in range(len(images))
]
for i in range(len(images)):
for col in range(len(crops)):
self._crop_grid[i][0, col].image = self.tonemap(crops[col].crop(images[i]))
else:
self._crop_grid = [
figuregen.Grid(num_cols=1, num_rows=len(crops))
for _ in range(len(images))
]
for i in range(len(images)):
for row in range(len(crops)):
self._crop_grid[i][row, 0].image = self.tonemap(crops[row].crop(images[i]))
# Add padding to the right of all but the last image
for i in range(len(images) - 1):
self._ref_grid[i].layout.set_padding(right=1)
self._crop_grid[i].layout.set_padding(right=1)
if self._crops_below:
self._ref_grid[i].layout.set_padding(bottom=1)
if self._crops_below:
self._ref_grid[-1].layout.set_padding(bottom=1)
else:
self._ref_grid[-1].layout.set_padding(right=1)
# Put error values underneath the columns
if self._crops_below:
for i in range(len(images)):
# if i > 0:
# err = self.error_string(i - 1, self.errors)
# else:
# err = self.error_metric_name
if add:
self._crop_grid[i].set_title("bottom", method_names[i])
self._crop_grid[i].layout.set_title("bottom", 6, 1, 8)
else:
pass # TODO
# TODO this requires titles spanning multiple grids (the image and its crops)!
# error_strings = [ f"{self.error_metric_name}" ]
# error_strings.extend([ self.error_string(i, self.errors) for i in range(len(self.errors)) ])
# self._crop_grid.set_col_titles("bottom", error_strings)
# self._crop_grid.layout.set_padding(column=1, row=1)
# self._crop_grid.layout.set_col_titles("bottom", fontsize=8, field_size_mm=2.8, offset_mm=0.5)
# If given, show method names on top
# TODO combine with error values, and always show both or neither
# if method_names is not None:
# self._crop_grid.set_col_titles("top", method_names)
# self._crop_grid.layout.set_col_titles("top", fontsize=8, field_size_mm=2.8, offset_mm=0.25)
# self._ref_grid.copy_layout(self._crop_grid)
# self._ref_grid.layout.set_padding(right=1)
# TODO set appropriate paddings for alignment etc
def error_string(self, index, errors):
""" Generates the human-readable error string for the i-th element in a list of error values.
Args:
index: index in the list of errors
errors: list of error values, one per method, in order
"""
if self.use_latex and index == np.argmin(errors):
return f""
elif self.use_latex:
return f""
else:
return f""
def error_metric_name(self) -> str:
return ""
def main(data_root,image_file_1,image_file_2,image_file_3,dataset_type,ours_method,crops_1,crops_2,crops_3,width_cm,output_image,ours_method_1=None,ours_method_2=None,ours_method_3=None):
data_root = os.path.join(data_root)
original_image_1 = sio.read(os.path.join(data_root,"original",dataset_type,image_file_1))
# 写完了你在这个里面直接运行就可以
KinD_image_1= sio.read(os.path.join(data_root,"KinD",dataset_type,image_file_1))
LIME_image_1= sio.read(os.path.join(data_root,"LIME",dataset_type,image_file_1))
NPE_image_1 = sio.read(os.path.join(data_root,"NPE",dataset_type,image_file_1))
SRIE_image_1 = sio.read(os.path.join(data_root,"SRIE",dataset_type,image_file_1))
ZeroDCE_image_1 = sio.read(os.path.join(data_root,"ZeroDCE",dataset_type,image_file_1))
ours_image_1 = sio.read(os.path.join(data_root,ours_method_1 if ours_method_1 else ours_method,dataset_type,image_file_1))
original_image_2 = sio.read(os.path.join(data_root,"original",dataset_type,image_file_2))
# 写完了你在这个里面直接运行就可以
KinD_image_2= sio.read(os.path.join(data_root,"KinD",dataset_type,image_file_2))
LIME_image_2= sio.read(os.path.join(data_root,"LIME",dataset_type,image_file_2))
NPE_image_2 = sio.read(os.path.join(data_root,"NPE",dataset_type,image_file_2))
SRIE_image_2 = sio.read(os.path.join(data_root,"SRIE",dataset_type,image_file_2))
ZeroDCE_image_2 = sio.read(os.path.join(data_root,"ZeroDCE",dataset_type,image_file_2))
ours_image_2 = sio.read(os.path.join(data_root,ours_method_2 if ours_method_2 else ours_method,dataset_type,image_file_2))
original_image_3 = sio.read(os.path.join(data_root,"original",dataset_type,image_file_3))
# 写完了你在这个里面直接运行就可以
KinD_image_3= sio.read(os.path.join(data_root,"KinD",dataset_type,image_file_3))
LIME_image_3= sio.read(os.path.join(data_root,"LIME",dataset_type,image_file_3))
NPE_image_3 = sio.read(os.path.join(data_root,"NPE",dataset_type,image_file_3))
SRIE_image_3 = sio.read(os.path.join(data_root,"SRIE",dataset_type,image_file_3))
ZeroDCE_image_3 = sio.read(os.path.join(data_root,"ZeroDCE",dataset_type,image_file_3))
ours_image_3 = sio.read(os.path.join(data_root,ours_method_3 if ours_method_3 else ours_method,dataset_type,image_file_3))
output_image = os.path.abspath(output_image)
figure_1 = MyCrops(
reference_image=original_image_1,
method_images=[
KinD_image_1,
LIME_image_1,
NPE_image_1,
SRIE_image_1,
ZeroDCE_image_1,
ours_image_1
],
crops=[
Cropbox(top=crop[0], left=crop[1], height=crop[2], width=crop[3], scale=crop[4]) for crop in crops_1
],
# scene_name="Pool",
method_names=["Reference", "KinD", "LIME", "NPE", "SRIE", "ZeroDCE", "Ours"],
use_latex=True
).figure
figure_2 = MyCrops(
reference_image=original_image_2,
method_images=[
KinD_image_2,
LIME_image_2,
NPE_image_2,
SRIE_image_2,
ZeroDCE_image_2,
ours_image_2
],
crops=[
Cropbox(top=crop[0], left=crop[1], height=crop[2], width=crop[3], scale=crop[4]) for crop in crops_2
],
# scene_name="Pool",
method_names=["Reference", "KinD", "LIME", "NPE", "SRIE", "ZeroDCE", "Ours"],
use_latex=True
).figure
figure_3=MyCrops(
reference_image=original_image_3,
method_images=[
KinD_image_3,
LIME_image_3,
NPE_image_3,
SRIE_image_3,
ZeroDCE_image_3,
ours_image_3
],
crops=[
Cropbox(top=crop[0], left=crop[1], height=crop[2], width=crop[3], scale=crop[4]) for crop in crops_3
],
method_names=["Reference", "KinD", "LIME", "NPE", "SRIE", "ZeroDCE", "Ours"],
use_latex=True,
add=True
).figure
# scene_name="Pool",
figuregen.figure([figure_1[0],figure_1[1],figure_2[0],figure_2[1],figure_3[0],figure_3[1]], width_cm=width_cm, filename=output_image)
# grid = figuregen.Grid(3,1)
# grid[0,0].set_image(figure)
# grid[1,0].set_image(figure)
# grid[2,0].set_image(figure)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--config", type=str, default="./config/compare3_1.yaml")
args = parser.parse_args()
with open(args.config, "r") as f:
config = yaml.safe_load(f)
main(**config)

85
output.html Normal file

File diff suppressed because one or more lines are too long

BIN
output.pdf Normal file

Binary file not shown.

85
pool_with_template.html Normal file

File diff suppressed because one or more lines are too long

BIN
result/compare1_1.pdf Normal file

Binary file not shown.

BIN
result/compare2_1.pdf Normal file

Binary file not shown.

BIN
result/compare3_1.pdf Normal file

Binary file not shown.

BIN
result/compare4_1.pdf Normal file

Binary file not shown.

BIN
result/compare5_1.pdf Normal file

Binary file not shown.

9
run.sh Normal file
View File

@ -0,0 +1,9 @@
python main.py --config ./config/compare1_1.yaml
python main.py --config ./config/compare2_1.yaml
python main.py --config ./config/compare3_1.yaml
python main.py --config ./config/compare4_1.yaml
python main.py --config ./config/compare5_1.yaml