Return np.average from masked numpy array [closed]

Fisheye All Sky Images


Idea: Only Calculate with Sky Area Pixels (Solarpoweranalysis)

e.g. static circle

def get_sky_area(radius, centre, image_name):
    img = Image.open(str(image_name))
    cv2_img = np.array(img)
    cv2_img = cv2.cvtColor(cv2_img, cv2.COLOR_RGB2BGR)
    sky = cv2_img.copy()
    mask = np.zeros(sky.shape[:2], dtype="uint8")
    cv2.circle(mask, centre, radius, 255, -1)
    # apply the mask to our image
    masked = cv2.bitwise_and(sky, sky, mask=mask)
    avgR = np.mean(masked[:,:,0])
    avgG = np.mean(masked[:,:,1])
    avgB = np.mean(masked[:,:,2])
    print("Mean of channel R: ", avgR)
    print("Mean of channel G: ", avgG)
    print("MEan of channel B: ", avgB)
    
    #cv2.imshow("sky", sky)
    #cv2.imshow("mask", mask)
    #cv2.imwrite('sky_image.png', masked[:,:,2])
    print("Saved Sky image as sky_image")
    #cv2.imshow("Mask applied to image", masked)
    #cv2.waitKey()
    return avgR, avgG, avgB

Is there smarter way for calculating with masked matric entries?

    CENTRE= (574, 335)
    RADIUS = 353   
    IMAGE_NAME = "path/to/1669190042.jpg" #saved in utc_time_format
    avgR, avgG, avgB = get_sky_area(radius = RADIUS, centre = CENTRE, image_name=IMAGE_NAME)


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation