image-thresholding

Using masks to apply different thresholds to different parts of an image

拟墨画扇 提交于 2021-02-10 07:08:24
问题 I have an image, in which I want to threshold part of the image within a circular region, and then the remainder of the image outside of this region. Unfortunately my attempts seem to be thresholding the image as a whole, ignoring the masks. How can this be properly achieved? See code attempt below. def circular_mask(h, w, centre=None, radius=None): if centre is None: # use the middle of the image centre = [int(w / 2), int(h / 2)] if radius is None: # use the smallest distance between the

How to obtain an image's single colour channel without using the split function in OpenCV Python?

你离开我真会死。 提交于 2020-08-09 08:49:26
问题 I'd like to highlight a hand for real-time gesture recognition. I observed that the image of a hand gets highlighted differently for different colour channels using the cv2.imsplit function. But this split function is very costly in terms of time. I'm not able to perform the same functionality using Numpy indexing (as given on the official page) 回答1: You can use numpy's slice: import cv2 import numpy as np ## read image as np.ndarray in BGR order img = cv2.imread("test.png") ## use OpenCV

Otsu's method thresholding making a 'shroud'

亡梦爱人 提交于 2019-12-25 18:14:05
问题 I'm trying to threshold an image using Otsu's method in Opencv: Although when I threshold it, some parts of the picture are completely surrounded by white and creates and ends up in Opencv not detecting all the contours in the image. This is what I get when I do Otsu's method thresholding using ret,thresh=cv2.threshold(blurred,0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) : EDIT: Some people have asked for the code I am using so here it is: gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) cv2

Otsu's method thresholding making a 'shroud'

≡放荡痞女 提交于 2019-12-25 18:12:58
问题 I'm trying to threshold an image using Otsu's method in Opencv: Although when I threshold it, some parts of the picture are completely surrounded by white and creates and ends up in Opencv not detecting all the contours in the image. This is what I get when I do Otsu's method thresholding using ret,thresh=cv2.threshold(blurred,0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) : EDIT: Some people have asked for the code I am using so here it is: gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) cv2

Using Skimage adaptive thresholding on an image and getting the output

无人久伴 提交于 2019-12-24 20:54:28
问题 I am trying to use scikit-image's adaptive threshold on my image. I tested out their sample code from HERE import matplotlib.pyplot as plt from skimage import data from skimage.filters import threshold_otsu, threshold_adaptive image = data.page() global_thresh = threshold_otsu(image) binary_global = image > global_thresh block_size = 35 binary_adaptive = threshold_adaptive(image, block_size, offset=10) fig, axes = plt.subplots(nrows=3, figsize=(7, 8)) ax0, ax1, ax2 = axes plt.gray() ax0

Automatic contrast and brightness adjustment of a color photo of a sheet of paper with OpenCV

允我心安 提交于 2019-12-17 15:22:22
问题 When photographing a sheet of paper (e.g. with phone camera), I get the following result (left image) (jpg download here). The desired result (processed manually with an image editing software) is on the right: I would like to process the original image with openCV to get a better brightness/contrast automatically (so that the background is more white) . Assumption: the image has an A4 portrait format (we don't need to perspective-warp it in this topic here), and the sheet of paper is white

I want to apply a threshold to pixels in image using python. Where did I make a mistake?

我的未来我决定 提交于 2019-12-11 07:50:43
问题 I want to generate the output that is a threshold. And my error: img_thres = n_pix[y, x] TypeError: 'int' object is not subscriptable import cv2 import numpy as np import matplotlib as plt img = cv2.imread("cicek.png",0) img_rgb = cv2.imread("cicek.png") h = img.shape[0] w = img.shape[1] img_thres= [] n_pix = 0 # loop over the image, pixel by pixel for y in range(0, h): for x in range(0, w): # threshold the pixel pixel = img[y, x] if pixel < 0.5: n_pix = 0 img_thres = n_pix[y, x] cv2.imshow(

Temperature is black after thresholding

谁说胖子不能爱 提交于 2019-12-08 11:52:22
问题 I want to show the temperature based on the density. Following are the function that Im using, def add_heat(heatmap, bbox_list): for i in range(len(bbox_list)): rect = trackers[i].get_position() heatmap[int(rect.left()):int(rect.top()), int(rect.right()):int(rect.bottom())] += 1 return heatmap def apply_threshold(heatmap, threshold): # Zero out pixels below the threshold heatmap[heatmap <= threshold] = 0 # Return thresholded map cv2.imwrite("heatmap.png",heatmap) return heatmap add_heat

Automatic contrast and brightness adjustment of a color photo of a sheet of paper with OpenCV

谁都会走 提交于 2019-11-29 21:02:44
When photographing a sheet of paper (e.g. with phone camera), I get the following result (left image) (jpg download here ). The desired result (processed manually with an image editing software) is on the right: I would like to process the original image with openCV to get a better brightness/contrast automatically (so that the background is more white) . Assumption: the image has an A4 portrait format (we don't need to perspective-warp it in this topic here), and the sheet of paper is white with possibly text/images in black or colors. What I've tried so far: Various adaptive thresholding