t2ac32/PSNR-HVS-M-for-python

While run I get this Issure: too many values to unpack

Closed this issue · 7 comments

Input is a 8 bit .png picture and
input Pic Shape(840, 1680, 3)


ValueError Traceback (most recent call last)
in
4 noise = np.array(img_n)
5 print(imask.shape)
----> 6 p1, p2 = psnrhvsm(noise,imask,wstep=8)
7
8 print('p_hvs_m: {:.0f} dB'.format(p1))

in psnrhvsm(img1, img2, wstep, *args, **kwargs)
122
123 LenXY= img1.shape
--> 124 ( LenX, LenY) = LenXY
125 print('lenx: {:.0f}, leny: {:.0f}'.format(LenX,LenY))
126

ValueError: too many values to unpack (expected 2)

if I use it as import i get:

~/Documents/BA 13022020/programme/PicCompare/psnrhvsm/init.py in psnrhvsm(img1, img2, wstep, *args, **kwargs)
100 return p_hvs_m,p_hvs
101
--> 102 if img1.size() != img2.size():
103 p_hvs_m=- Inf
104 p_hvs=- Inf

TypeError: 'int' object is not callable

can you help please :)?

did you tried running the Baboon Test?
Can you link the images being used or at least the code where you are loading them into the module?


Edit:

Just checked and apparently I haven't give much maintenance and there are some changes on numpy such as flatten requiring the order of the array being specified by a string.

I'll leave this thread open and I'm opening a maintenance branch.
Please stay tuned for the update of the library.

Hey I´m writing a analysis programm to compare 16bit png hdr pictures.

I would normalize the pictues to 0,1 before testing them.

Here I wanted to add your PSNR-HVS-M inputing two pictures and getting the PSNR-HVS-M as a return.

greetings Nico

I updated the project:
Updated master name to main (please reclone the project)
Fixed a problem with numpy flatten function.

Although because of where you are having the problem I think the reason is the number of channels in your Input.

There are two possible solutions:

For Pure 8bit (grayscale/black and white) images :

  • If your image is 8bit (black and white or grayscale) one channel of the image should be enough.
  • so using and input of shape (840, 1680) should be enough. Notice im just ignoring the channels dimensions.

If you are using COLOR IMAGES :

For color images with three RGB values per pixel, the definition of PSNR is the same except the MSE is the sum over all squared value differences. See PSNR WIK (Application in color images)

  • you can send each channel individually and sum the result of each PSNR.
  • this should be enough if your images are normalized.
  • If your images are not normalized: convert the image to the desired color space and report the PSNR per channel of the selected color space.

Hey I´m writing a analysis programm to compare 16bit png hdr pictures.

I would normalize the pictues to 0,1 before testing them.

Here I wanted to add your PSNR-HVS-M inputing two pictures and getting the PSNR-HVS-M as a return.

greetings Nico

That sounds cool!
Could you please add a link to this project repo in your ReadMe file once the implementation is successful?

So my problem seems to be that I want to test 2 images 840, 1680, 3 into the function and It doesnt like that. So my solution would be?

sending in 840,1680,[0] than 840,1680,[1] and than 840,1680,[2] add them all together and than divide it by 3?

Sorry I´m new to this type of Image quality mesurments

So my problem seems to be that I want to test 2 images 840, 1680, 3 into the function and It doesnt like that. So my solution would be?

sending in 840,1680,[0] than 840,1680,[1] and than 840,1680,[2] add them all together and than divide it by 3?

Sorry I´m new to this type of Image quality mesurments

That's right, that is the way to do it will look like this taking into account the code you sent as reference:


       def ms_SSIM(a,b): #or MS psnr 
        #check dimensions of A and B
        A_dims = a.ndim
        B_dims = b.ndim
        
        if A_dims != B_dims:
        #images have different dimensions
        else:
        #if dims are 2  e.j (840,1680)
            MS_SSIM_val = ms_ssim( a, b, data_range=1, size_average=False )
        #elif dims are 3:

            #assuming your third dimension is the number of channels
            #check number of channels for both images are the same
            a_channels  = a.shape[2]
            b_channels = b.shape[2]
            PSNR_per_channel = []
     
           if a_channesl == b_channels:
           for c in range(0, a_channels)
                  # Compute PSNR per channel
                   #notice how only the channel for image a and b is being processed
               MS_SSIM_val = ms_ssim( a[c], b[c], data_range=1, size_average=False )
               
              #save chanel's PSNR 
              PSNR_per_channel.append(MS_SSIM_val)
       #compute average PSNR for image a and b:
       avg_PSNR = reduce(lambda a, b: a + b, PSNR_per_channel) / len(PSNR_per_channel)     
    
return 0


This is just boiler plate code for you to see the main idea. For sure it can be optimized or written better.

Closing issue due to reporter's absence.