本文整理汇总了Python中parameters.Parameters.setColorRanges方法的典型用法代码示例。如果您正苦于以下问题:Python Parameters.setColorRanges方法的具体用法?Python Parameters.setColorRanges怎么用?Python Parameters.setColorRanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parameters.Parameters
的用法示例。
在下文中一共展示了Parameters.setColorRanges方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: countRegions
# 需要导入模块: from parameters import Parameters [as 别名]
# 或者: from parameters.Parameters import setColorRanges [as 别名]
def countRegions():
# Requires: -the first command line argument is the name of the
# image to be segmented
# -the second command line argument is the color space being
# used, either RGB, HSV, or HLS
# Effects: -calls closure with count foreground argument on, returns
# count of distinct foreground objects
colorSpace = argv[2].lower()
if not (colorSpace in ["rgb", "hsv", "hls"]):
print "Second argument not one of RGB, HSV, or HLS"
print "The first argument should be the name of the image to be segmented"
print "Followed by the desire color space representation"
exit(1)
try:
image = Image.open(argv[1])
imageData = colorSpaceConvert(list(image.getdata()), argv[2].lower())
except:
print "Invalid or no image name given"
print "The first argument should be the name of the image to be segmented"
print "Followed by the desire color space representation"
exit(1)
if colorSpace == "rgb":
redMinMax = raw_input("Red min-max, between 0 and 255: ")
greenMinMax = raw_input("Green min-max, between 0 and 255: ")
blueMinMax = raw_input("Blue min-max, between 0 and 255: ")
redMinMax = [float(x) / 255.0 for x in redMinMax.split()]
greenMinMax = [float(x) / 255.0 for x in greenMinMax.split()]
blueMinMax = [float(x) / 255.0 for x in blueMinMax.split()]
colorRanges = [redMinMax, greenMinMax, blueMinMax]
elif colorSpace == "hsv":
hueMinMax = raw_input("Hue min-max, between 0 and 360: ")
satMinMax = raw_input("Saturation min-max, between 0 and 100: ")
valMinMax = raw_input("Value min-max, between 0 and 100: ")
hueMinMax = [float(x) / 360.0 for x in hueMinMax.split()]
satMinMax = [float(x) / 100.0 for x in satMinMax.split()]
valMinMax = [float(x) / 100.0 for x in valMinMax.split()]
colorRanges = [hueMinMax, satMinMax, valMinMax]
else:
hueMinMax = raw_input("Hue min-max, between 0 and 360: ")
lightMinMax = raw_input("Lightness min-max, between 0 and 100: ")
satMinMax = raw_input("Saturation min-max, between 0 and 100: ")
hueMinMax = [float(x) / 360.0 for x in hueMinMax.split()]
lightMinMax = [float(x) / 100.0 for x in lightMinMax.split()]
satMinMax = [float(x) / 100.0 for x in satMinMax.split()]
colorRanges = [hueMinMax, lightMinMax, satMinMax]
param = Parameters()
param.setImageSize(image.size)
param.setColorRanges(colorRanges)
seg = segmentation.colorSegmenter()
mask = seg.segmentImage(imageData, param, True)
close = closure.closure()
close.segmentRegions(mask, param, 0, True, False)