Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for Review of NIQE Implementation #234

Open
songminkyu opened this issue Dec 16, 2024 · 1 comment
Open

Request for Review of NIQE Implementation #234

songminkyu opened this issue Dec 16, 2024 · 1 comment

Comments

@songminkyu
Copy link

songminkyu commented Dec 16, 2024

Hi there,

I am writing to seek your help in reviewing my implementation of the NIQE (Natural Image Quality Evaluator) logic. I have attached my code below and would appreciate it if you could verify whether it is functioning correctly or suggest any improvements.

import pyiqa
import torch
import torch.nn as nn
import cv2
import numpy as np

def calculate_niqe(self, image: np.ndarray) -> Tuple[bool, float]:
    # Convert image to [N, C, H, W] format and normalize to [0, 1] range
    # image: (H, W, C)
    im_t = torch.FloatTensor(image.transpose(2, 0, 1)[None]).to('cuda') / 255.0

    # Create NIQE metric object (using GPU)
    niqe_metric = pyiqa.create_metric("niqe", device='cuda')

    # Calculate NIQE score
    score_tensor = niqe_metric(im_t)
    score = score_tensor.item()

    # Determine quality based on threshold (lower NIQE score means better quality)
    is_good = score < self.niqe_threshold

    return is_good, score

image_path = "c:\\Users\\USER\\Desktop\\M1JUHjD2_4x.jpg"
image = cv2.imread(image_path)
isgood, score = calculate_niqe(image)

This code is designed to evaluate the quality of an image by calculating its NIQE score. I would particularly like feedback on the following aspects:

  1. Whether the image preprocessing and transformation are handled correctly

  2. If the creation of the NIQE metric object and GPU utilization are implemented properly

  3. The method used for calculating the NIQE score and evaluating image quality

Any feedback you can provide would be greatly appreciated. Thank you for your time and assistance!
(If the implementation of the niqe logic is wrong, I would appreciate it if you could give me feedback on how to implement it specifically.)

@chaofengc
Copy link
Owner

Your implementation appears to be correct! If you have any doubts about your results, you can compare them with the example outputs provided in the following file: calibration_summary.csv. The input images can be found in the ResultsCalibra/dist_dir directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants