Returning Threshold Values
I am trying to return the average threshold value for a binary ROI, however, I keep on getting a weird output.
My code is :
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 is null for some reason
roi_gray = cv2.rectangle(edge, (i,j), (i+10, j+10), (128, 128, 128), 1)
cv2.imshow('ROI', roi_gray)
retval, threshold = cv2.threshold(roi_gray, 10, 255, cv2.THRESH_OTSU)
threshed_roi_gray = threshold
print (threshed_roi_gray)
#see what threshold value is, assign roi a 1 or 0, and add it to list to be traversed
cv2.imshow('Image Edges', edge)
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()
And the output values I get are:
[255 0 0 ..., 0 0 0]
[255 0 0 ..., 0 0 0]]
[[255 255 255 ..., 0 0 0]
[255 0 0 ..., 0 0 0]
[255 0 0 ..., 0 0 0]
....
I am confused what these values are. I thought that [255 0 0] was the color code for red, while my image is only black and white. I am also confused why 2 data values are returned for each ROI threshold, instead of just 1. I would appreciate your help, thanks.