threshold

机器人的运动范围

旧时模样 提交于 2020-01-25 01:22:00
原题目: 地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。但是,它不能进入方格(35,38),因为3+5+3+8 = 19。请问该机器人能够达到多少个格子? 题目分析: 1.从(0,0)开始走,每成功走一步标记当前位置为true,然后从当前位置往四个方向探索, 返回1 + 4 个方向的探索值之和。 2.探索时,判断当前节点是否可达的标准: 1)当前节点在矩阵内; 2)当前节点未被访问过; 3)当前节点满足limit限制; 代码实现: public class Solution { public int movingCount(int threshold, int rows, int cols) { boolean[] visited=new boolean[rows*cols]; return movingCountCore(threshold, rows, cols, 0,0,visited); } private int movingCountCore(int threshold, int rows, int cols, int row,int col,boolean[]

Keras实例:自定义损失函数/指标函数

随声附和 提交于 2020-01-19 12:11:48
在训练模型的时候,Keras提供了许多损失函数供我们使用,但是即便如此,我们也会有遇到需要用自己的损失函数的情况,这样我们就要自定义一个损失函数。比如我现在需要定义一个损失函数,类似于relu函数,低于threshold的loss为0,大于threshold的loss就是他们之间的差。注意我们在定义损失函数的时候,必须可以求导。任何损失函数必须有y_true, y_pred两个参数,他们的类型为tensor。 def relu_loss ( y_true , y_pred , threshold = 1 ) : if not K . is_tensor ( y_pred ) : y_pred = K . constant ( y_pred ) y_true = K . cast ( y_true , y_pred . dtype ) return K . sum ( K . cast ( K . greater ( K . abs ( y_pred - y_true ) , threshold ) , K . floatx ( ) ) * K . abs ( y_pred - y_true ) ) 在定义完之后,我们就可以通过名字把损失函数和指标函数给模型了。 model . compile ( optimizer = 'rmsprop' , loss = relu_loss ,

ImageMagick - How do I flatten white levels to pure white?

倖福魔咒の 提交于 2020-01-13 02:53:10
问题 I have a png image with a white background which I'd like to turn transparent. This is fairly simple with this command: $ convert image.png -transparent white image-trans.png However, if the white background is not completely white (i.e, #FFFFFF , rgb(255,255,255) , etc), then this doesn't work well. Is there a way to set reduce everything below a certain threshold to complete white? Thanks. 回答1: The commandline option you are looking for is -white-threshold value{%} So a command of convert

Object detecting using thresholding

蹲街弑〆低调 提交于 2020-01-10 04:23:20
问题 I'm working on a program in matlab to detect an object in a sequence of images. The object I'm trying to detect a red ball. First, I tried to use thresholding to segment the ball from the image, but I couldn't do that. I couldn't get rid of the shadow under the ball. Any Ideas how to get rid of the small part under the ball? My second question is, I want to make sure that the object I'm looking for is a red ball. my code will detect any red object, I want to make sure its a circle. My code:

Opencv之threshold

不打扰是莪最后的温柔 提交于 2020-01-06 17:19:11
一、参考: 1、Opencv之图像固定阈值二值化处理threshold https://blog.csdn.net/qq_37385726/article/details/82015545 ①总结:适合多看 来源: CSDN 作者: 智勇双全的智勇 链接: https://blog.csdn.net/qq_40544338/article/details/103858411

OpenCV threshold with mask

こ雲淡風輕ζ 提交于 2020-01-06 16:20:56
问题 I'm trying to use OpenCV's cv::threshold function (more specific THRESH_OTSU ), only that I'd like to do it with a mask (any shape), so that the outside (background) is ignored during calculation. Image is single channel (as it must be), red color bellow is only to mark an example polygon on an image. I tried using adaptiveThreshold , but there are a couple of problems that make it inappropriate in my case. 回答1: In general, you can simply compute the threshold using cv::threshold , and then

Compare two vectors of numbers based on threshold of tolerance (±) of 0.5

浪尽此生 提交于 2020-01-05 04:22:07
问题 I have two vectors g and h . I want to compare the numbers in these two vectors and find out whether there are any common elements between them. But the common elements do not have to be exactly the same and can be within a range of (-0.5, +0.5) . Therefore, g±0.5 is being compared with h±0.5 . g <- c(0.5, 5956.3, 38, 22.666, 590.3, 21.992, 9.3) h <- c(0.7, 99.2, 39, 30, 21.68, 9.4, 22.333, 0.001, 0.000222, 9.999) As an example, in the two vectors above, 0.5 from g and 0.7 from h match

R: Finding the nearest raster cell within a threshold calculated between two rasters

♀尐吖头ヾ 提交于 2020-01-01 23:19:50
问题 I have two perfectly overlapping rasters (same extents and cell size). For every cell in one raster (i.e. for every XY), I would like to determine the Euclidean geographical distance to the closest cell within a given threshold difference between the rasters. Put another way: raster1 and raster2 measure some variable Z. I have a threshold difference for Z values (t) which constitutes a "matching" value (or "close enough") between raster1 and raster2. For each reference cell in raster1, I need

How do I define color groups based on numerical threshold values for ggplot2 scatterplot

夙愿已清 提交于 2020-01-01 11:39:00
问题 I have a data set that contains 2 variables x = event number & y = assay amplitude. I am trying to create a scatterplot in ggplot2 where all of the points that are > 3000 are colored in one color and all of the points < 3000 are in a different color. I can get the plot and change the color for all data points, but can't figure out how to define a color scheme based on the value threshold. Here is a sample of the data I'm using: dat <- data.frame(x=c(399, 16022, 14756, 2609, 1131, 12135, 7097,

Return coordinates that passes threshold value for bounding boxes Google's Object Detection API

陌路散爱 提交于 2019-12-31 03:55:25
问题 Does anyone know how to get bounding box coordinates which only passes threshold value? I found this answer (here's a link), so I tried using it and done the following: vis_util.visualize_boxes_and_labels_on_image_array( image, np.squeeze(boxes), np.squeeze(classes).astype(np.int32), np.squeeze(scores), category_index, use_normalized_coordinates=True, line_thickness=1, min_score_thresh=0.80) for i,b in enumerate(boxes[0]): ymin = boxes[0][i][0]*height xmin = boxes[0][i][1]*width ymax = boxes