Giter Site home page Giter Site logo

Comments (5)

HuiZeng avatar HuiZeng commented on June 2, 2024

For this purpose, you need to write some lines of code to read and process a set of images.
You can check image_adaptive_lut_evaluation.py for reference.

from image-adaptive-3dlut.

xuhui1994 avatar xuhui1994 commented on June 2, 2024

from image-adaptive-3dlut.

Gager-Git-life avatar Gager-Git-life commented on June 2, 2024

from image-adaptive-3dlut.

Serendipity-55428 avatar Serendipity-55428 commented on June 2, 2024

非常感谢你的帮助,这份代码有些乱码,你能用txt文件保存再发给我吗?

Could you forward this txt to me, please? My mailbox is [email protected] and I'm curious if you've successfully tested a video in in demo_eval.py. I noticed that the author took part in the competition of NAIC2019 4K HDR and won the championship , which used this method for a video.

from image-adaptive-3dlut.

erbaymustafa avatar erbaymustafa commented on June 2, 2024

You can use the code below...

***Just describe the folder that contains the images on line 75 and edit the split method according to your file path on line 106
***Create a folder named 'output'

import argparse
import torch
import os
import numpy as np
import cv2
from PIL import Image
import time
from models_x import *
import torchvision_x_functional as TF_x
import torchvision.transforms.functional as TF
import glob

parser = argparse.ArgumentParser()

parser.add_argument("--image_dir", type=str, default="demo_images", help="directory of image")
parser.add_argument("--image_name", type=str, default="frame254.tif", help="name of image")
parser.add_argument("--input_color_space", type=str, default="sRGB", help="input color space: sRGB or XYZ")
parser.add_argument("--model_dir", type=str, default="pretrained_models", help="directory of pretrained models")
parser.add_argument("--output_dir", type=str, default="demo_results", help="directory to save results")
opt = parser.parse_args()
opt.model_dir = opt.model_dir + '/' + opt.input_color_space
#opt.image_path = opt.image_dir + '/' + opt.input_color_space + '/' + opt.image_name

os.makedirs(opt.output_dir, exist_ok=True)

# use gpu when detect cuda
cuda = True if torch.cuda.is_available() else False
# Tensor type
Tensor = torch.cuda.FloatTensor if cuda else torch.FloatTensor

criterion_pixelwise = torch.nn.MSELoss()
LUT0 = Generator3DLUT_identity()
LUT1 = Generator3DLUT_zero()
LUT2 = Generator3DLUT_zero()
#LUT3 = Generator3DLUT_zero()
#LUT4 = Generator3DLUT_zero()
classifier = Classifier()
trilinear_ = TrilinearInterpolation() 

if cuda:
    LUT0 = LUT0.cuda()
    LUT1 = LUT1.cuda()
    LUT2 = LUT2.cuda()
    #LUT3 = LUT3.cuda()
    #LUT4 = LUT4.cuda()
    classifier = classifier.cuda()
    criterion_pixelwise.cuda()

# Load pretrained models
LUTs = torch.load("%s/LUTs.pth" % opt.model_dir)
LUT0.load_state_dict(LUTs["0"])
LUT1.load_state_dict(LUTs["1"])
LUT2.load_state_dict(LUTs["2"])
#LUT3.load_state_dict(LUTs["3"])
#LUT4.load_state_dict(LUTs["4"])
LUT0.eval()
LUT1.eval()
LUT2.eval()
#LUT3.eval()
#LUT4.eval()
classifier.load_state_dict(torch.load("%s/classifier.pth" % opt.model_dir))
classifier.eval()


def generate_LUT(img):

    pred = classifier(img).squeeze()
    
    LUT = pred[0] * LUT0.LUT + pred[1] * LUT1.LUT + pred[2] * LUT2.LUT #+ pred[3] * LUT3.LUT + pred[4] * LUT4.LUT

    return LUT


#Describe the folder that contains the images
path = glob.glob('***Images Folder Path***/*.jpg')
# ----------
#  test
# ----------
# read image and transform to tensor


for file in path:

    start = time.time()
    if opt.input_color_space == 'sRGB':
        img = cv2.imread(file)
        img = TF.to_tensor(img).type(Tensor)
    elif opt.input_color_space == 'XYZ':
        img = cv2.imread(opt.image_path, -1)
        img = np.array(img)
        img = TF_x.to_tensor(img).type(Tensor)
    img = img.unsqueeze(0)

    LUT = generate_LUT(img)

    # generate image
    _, result = trilinear_(LUT, img)
    
    # save image
    ndarr = result.squeeze().mul_(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to('cpu', torch.uint8).numpy()
    im = Image.fromarray(ndarr)
    im = np.array(im)
    
    finish = time.time()
    #you can change this split method for your file path 
    name_img = file.split('/')
    name_img = name_img[5]

    print(name_img)
    #Create a folder named output
    cv2.imwrite('output/'+ name_img , im)
    print('Image was enhanced')
    print('Time stamp: '+str(finish-start))
  

from image-adaptive-3dlut.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.