Ask Your Question
0

Find Average Intensity of ROI

asked 2018-03-16 05:26:12 -0600

Stephane gravatar image

I was wondering how to find the average intensity of a gray scaled ROI. I currently use the code below, however when I try to print

roi_gray_mean

I get the output in the console

<built-in method mean of numpy.ndarray object at 0x181c95b530>
<built-in method mean of numpy.ndarray object at 0x181c95b670>
<built-in method mean of numpy.ndarray object at 0x181c95b4e0>
......

Below is my code.

import cv2
import numpy as np

img = cv2.imread("/Users/2020shatgiskessell/Desktop/roomimage.jpg")
roomimg = cv2.resize(img, (0,0), fx=0.5, fy=0.5)
gray = cv2.cvtColor(roomimg, cv2.COLOR_BGR2GRAY)

#edge detection 
ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV)
edge = cv2.Canny(thresh, 100, 200)

#create nodes by iterating through 10x10 blocks and checking the neighbors

height,width,channels = roomimg.shape

for i in range (0,width,10):
    for j in range (0,height,10):
        roi_gray = gray[width: i+10,height: j+10]
        cv2.rectangle(edge, (i,j), (i+10, j+10), (128, 128, 128), 1)
        roi_gray_mean = roi_gray.mean
        print (roi_gray_mean)


cv2.imshow('Image Edges', edge)
if cv2.waitKey(0) & 0xff == 27:
    cv2.destroyAllWindows()
edit retag flag offensive close merge delete

Comments

roi_gray.mean() -- it's a method...

berak gravatar imageberak ( 2018-03-17 06:36:37 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-03-16 05:32:06 -0600

berak gravatar image

updated 2018-03-16 05:33:27 -0600

pick your favourite:

>>> help(cv2.mean)
>>> help(np.mean)
edit flag offensive delete link more

Comments

could you please elaborate what that means, thanks.

Stephane gravatar imageStephane ( 2018-03-17 06:12:11 -0600 )edit

your question was: Find Average Intensity of ROI

both methods above do that. really your problem is -- you don't read docs, but try to ask around.

berak gravatar imageberak ( 2018-03-17 06:35:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-16 05:26:12 -0600

Seen: 1,110 times

Last updated: Mar 16 '18