Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Permanent Nan in NP
#1
need to conduct some analysis of the image, do not go into the questions what this formula is, it does not matter.
import numpy as np
from PIL import Image
#np.seterr(divide='ignore', invalid='ignore')
image=Image.open('E://test.jpg')
imgr,imgg,imgb=image.split()
r=np.asarray(imgr).astype('float64')
g=np.asarray(imgg).astype('float64')
b=np.asarray(imgb).astype('float64')
vari=(g-r)/(g+r-b)
nan=0
a=[]
for i in range (len(vari)):
    for j in range(len(vari[i])):
        if np.isnan(vari[i][j]):
            print ('NAN object',i,j)
            a=[]
            if not np.isnan(vari[i-1][j-1]):
                a.append(vari[i-1][j-1])
            if not np.isnan(vari[i-1][j]):
                a.append(vari[i-1][j])
            if not np.isnan(vari[i-1][j+1]):
                a.append(vari[i-1][j+1])#1st
            if not np.isnan(vari[i][j-1]):
                a.append(vari[i][j-1])
            if not np.isnan(vari[i][j+1]):
                a.append(vari[i][j+1])
            if not np.isnan(vari[i+1][j-1]):
                a.append(vari[i+1][j-1])
            if not np.isnan(vari[i+1][j]):
                a.append(vari[i+1][j])
            if not np.isnan(vari[i+1][j+1]):
                a.append(vari[i+1][j+1])
            a=np.asarray(a)
            print ('array',a,'mean',np.mean(a))
            vari[i][j]=0   
            nan=nan+1
print('TOTAL NAN',nan)
for i in range (len(vari)):
    for j in range(len(vari[i])):
        if np.isnan(vari[i][j]):
            print ('new NAN object',i,j)
s=0
vari=vari.ravel()
vari2=list(vari)
for i in range(len(vari2)):
    s=s+vari[i]
Code explanations: I need to calculate np.std and np.mean of full 2d array. But there is NaN alltime, i tried to delete Nan in loop, and check sum, but it is NaN too
Reply


Messages In This Thread
Permanent Nan in NP - by Antigr - Jun-26-2018, 01:31 PM
RE: Permanent Nan in NP - by Larz60+ - Jun-26-2018, 02:50 PM
RE: Permanent Nan in NP - by Antigr - Jun-26-2018, 03:15 PM
RE: Permanent Nan in NP - by Larz60+ - Jun-26-2018, 03:40 PM
RE: Permanent Nan in NP - by Antigr - Jun-26-2018, 04:55 PM
RE: Permanent Nan in NP - by Larz60+ - Jun-26-2018, 05:15 PM
RE: Permanent Nan in NP - by Antigr - Jun-26-2018, 05:32 PM
RE: Permanent Nan in NP - by volcano63 - Jun-26-2018, 07:06 PM
RE: Permanent Nan in NP - by Antigr - Jun-27-2018, 01:19 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020