user288609
user288609

Reputation: 13055

the image processing areas to segment the regions based on their corresponding level of brightness

With respect to the image shown in the following, there are regions with different level of brightness. For instance, I marked two regions with red circles, i.e., 3 and 4; and use arrows to point two small regions, i.e., 1 and 2. What are the image processing algorithms that can segment the regions based on their respective brightness level, I also want to calculate the areas of these different regions.

enter image description here

Upvotes: 0

Views: 229

Answers (1)

Piotr Kurowski
Piotr Kurowski

Reputation: 366

You can use Otsu thresholding only on image region. First You can get only foreground of image (without black background) by thresholding. Then You can calculate threshold value with Otsu alogrithm for not 0 values. Then use this value to threshold image.

src = cv.imread(image_path)

#convert to gray scale
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY) 

#thresholding to find only white region of image, without black backgorund
ret3, th3 = cv.threshold(gray, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)

#erosion to delet some noises
cv.erode(th3, np.ones((5, 5), np.uint8), 1)

#get all values from image that are not equal 0 (are not background)
tempThresImg = gray[th3 != 0]

#get threshold value only for not black pixels
threshold, temp = cv.threshold(tempThresImg, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)  # using otsu threshold

#use threshold value on whole image
ret, thresh = cv.threshold(gray, threshold, 255, cv.THRESH_BINARY)

My results (with Your arrows):

After thresholding to get foreground: After thresholding to get foreground

Result: Result

You can change threshold value to get result depending on whether the algorithm has detected too much or too little.

Upvotes: 1

Related Questions