photosynthesis-team / piq

Measures and metrics for image2image tasks. PyTorch.
Apache License 2.0
1.41k stars 120 forks source link

Metric: MAD #187

Open leihuayi opened 4 years ago

leihuayi commented 4 years ago

Is your feature request related to a problem? Please describe. Most Apparent Distortion algorithm combines two measures depending on image quality, based on observance of how HVS works:

Describe the solution you'd like Implement metric in Pytorch

Describe alternatives you've considered I'm not so knowledgeable in Pytorch, but if you don't have time I can try taking care of this implementation based on the below Pytorch code

Additional context Original paper : https://s2.smu.edu/~eclarson/pubs/2010JEI_MAD.pdf Author matlab code (newest version): http://vision.eng.shizuoka.ac.jp/mad/MAD_index_2011_10_07.zip Pytorch code : https://github.com/dingkeyan93/IQA-optimization/blob/master/IQA_pytorch/MAD.py

I tested the pytorch code. It is pretty similar to the matlab code except that they do not "kill the edges" at the end of index calculations, but I did not verify the parts that were originally C code in the authors zip (ical_stat, ica_sdt, get_moments ...). The code works fine and can be called this way on GPU:

from mad import prepare_image, MAD

# img_1, img_2 rgb image in [0-255]
reference = prepare_image(img_1, repeatNum = 1).to(device)
degraded = prepare_image(img_2, repeatNum = 1).to(device)
model = MAD(channels=1).to(device)
return model(reference, degraded, as_loss=False).item()

where prepare_image is this code:

def prepare_image(image, resize = False, repeatNum = 1):
    if resize and min(image.size)>256:
        image = transforms.functional.resize(image,256)
    image = transforms.ToTensor()(image)
    return image.unsqueeze(0).repeat(repeatNum,1,1,1)
zakajd commented 3 years ago

Hi @leihuayi Same question here. If you didn't start working on MAD I'll assign it to another student 😄

Shamus98 commented 3 years ago

I want to take this issue

leihuayi commented 3 years ago

Hi @zakajd I hadn't planned to work on this implementation since I had put a link of a pytorch version to copy from on the description: https://github.com/dingkeyan93/IQA-optimization/blob/master/IQA_pytorch/MAD.py

@Shamus98 you are welcome to work on it ^^