Пример #1
0
 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
0
def run_with_cnn(image_filename="../Wheat_Images/004.jpg", ser_filename=None):
    '''
	Estimates the number of grains in a given image using a
	Convolutional neural network.

	Args:
		image_filename: The path to the image from which a grain count
			is to be obtained.

		ser_filename: path to serialized list of isub-images already extracted
		from the image from which a grain count is to be obtained.

	Returns:
		count: An estimate of the number of grains in the provided image.
	'''

    global img_data

    # Chop image up into sub-images and serilaise or just load serialised data if
    # it already exists.
    if (ser_filename == None and image_filename == "../Wheat_Images/004.jpg"):
        ser_filename = "../Wheat_Images/xxx_004.data"
    if (Helper.unserialize(ser_filename) == None):
        img = img_as_ubyte(io.imread(image_filename))
        roi_img = spectral_roi.extract_roi(img, [1])
        Helper.block_proc(roi_img, (20, 20), blockfunc)
        #Helper.serialize(ser_filename, img_data)
    else:
        img_data = Helper.unserialize(ser_filename)

    # classify
    r = CNN.classify(img_data[0],
                     model_file=None,
                     featureRepresentation='glcm',
                     shouldSaveResult=True)

    # Count number of '1s' in the result and return
    count = r.tolist().count(1)
    print("COUNT: {}".format(count))
    return count
Пример #3
0
def run_with_mlp(image_filename="../Wheat_Images/004.jpg", ser_filename=None):
    '''
	Estimates the number of grains in a given image using a
	Multilayer Perceptron neural network.

	Args:
		image_filename: The path to the image from which a grain count
			is to be obtained.

		ser_filename: path to serialized list of isub-images already extracted
		from the image from which a grain count is to be obtained.

	Returns:
		count: An estimate of the number of grains in the provided image.
    '''
    global img_data

    # Chop image up into sub-images and serilaise or just load serialised data if
    # it already exists.
    if(ser_filename == None and image_filename == "../Wheat_Images/004.jpg"):
		ser_filename = "../Wheat_Images/xxx_004.data"
    if(Helper.unserialize(ser_filename) == None):
        img = img_as_ubyte(io.imread(image_filename))
        roi_img = spectral_roi.extract_roi(img, [1])
        Helper.block_proc(roi_img, (20,20), blockfunc)
        #Helper.serialize(ser_filename, img_data)
    else:
        img_data = Helper.unserialize(ser_filename)

    # classify
    #MLP.build_model('glcm', iters=30, glcm_isMultidirectional=True)
    r = MLP.classify(img_data, featureRepresentation='glcm', shouldSaveResult=True)

    # Count number of '1s' in the result and return
    count = r.tolist().count(1)
    print("COUNT: {}".format(count))
    return count