本文整理汇总了Python中Helper.generate_random_id方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.generate_random_id方法的具体用法?Python Helper.generate_random_id怎么用?Python Helper.generate_random_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Helper
的用法示例。
在下文中一共展示了Helper.generate_random_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: didClickSubmitButton
# 需要导入模块: import Helper [as 别名]
# 或者: from Helper import generate_random_id [as 别名]
def didClickSubmitButton(self, event):
print(self.imageFilePath)
img = img_as_ubyte(io.imread(CLUSTER_IMAGE_FILENAME))
roi_img = spectral_roi.extract_roi(img, gui_checkbox_handlers.getSelectedClusters())
roi_img_filename = "{}.png".format(Helper.generate_random_id())
io.imsave(roi_img_filename, roi_img)
Display.show_image(roi_img, roi_img_filename)
示例2: classify
# 需要导入模块: import Helper [as 别名]
# 或者: from Helper import generate_random_id [as 别名]
def classify(img, featureRepresentation='image', model_file=CLASSIFIER_FILE, shouldSaveResult=False):
'''
Classifies a sub-image or list of sub-images as grain (1) or not grain (0).
Args:
img: Input sub-image or list of input sub-images.
featureRepresentation: Type of features to be used in classification.
Can ake of one of the values 'image', 'pca' or 'glcm'. Note that the
classifier must have also been built using the same
feature representation.
model_file: filepath of serialized classifier to be used.
shouldSaveResult: If this boolean flag is set to true, this function
will save the sub-images and their classifictions to the "Results"
folder after classification.
Return:
scalar or list of 1 if grain and 0 otherwise.
'''
if(isinstance(img, np.ndarray)):
img_features = None
if(featureRepresentation == 'image'):
img_features = img.flatten()
elif(featureRepresentation == 'pca'):
img_features = decomposition.PCA(n_components=8).fit_transform(img.flatten())
elif(featureRepresentation == 'glcm'):
img_features = Helper.get_textural_features(img, 1, True)
clf = get_model(model_file)
return clf.predict(img_features.reshape(1,-1))
elif(isinstance(img, list)):
if(featureRepresentation == 'glcm'):
sample_size = 16
else:
sample_size = 20*20
test_data = np.zeros((len(img), sample_size))
i = 0
for image in img:
if(featureRepresentation == 'image'):
test_data[i] = image.flatten()
elif(featureRepresentation == 'pca'):
test_data[i] = decomposition.PCA(n_components=8).fit_transform(image.flatten())
elif(featureRepresentation == 'glcm'):
test_data[i] = Helper.get_textural_features(image, 1, True)
i = i+1
clf = get_model(model_file)
result = clf.predict(test_data)
if(shouldSaveResult == True):
# Save image with result in filename
if os.path.exists("Results"):
shutil.rmtree("Results")
os.makedirs("Results")
for i in xrange(0,len(img)):
io.imsave("Results/{}_{}.png".format(Helper.generate_random_id(8), result[i]), img[i])
else:
return None
示例3: block_process
# 需要导入模块: import Helper [as 别名]
# 或者: from Helper import generate_random_id [as 别名]
def block_process(img):
func = lambda block: io.imsave("Block/{}.png".format(Helper.generate_random_id()), block)#Display.save_image("Block/{}.png".format(Helper.generate_random_id()), block)
Helper.block_proc(img, (50,1900), func)