def mark_plot(image, f_poly_power = -1, plot_pts_size=50): """ Searches for plot axes and point marks then constructs a poly to interpolate a diagram :param image: image to operate on :param f_poly_power: one can specifically set power of interpolation poly :param plot_pts_size: number of points in drawn plot :return: """ draw = ImageDraw.Draw(image) width = image.size[0] height = image.size[1] pix = image.load() image_data = convert_image_to_data_buffer(pix, width, height, channels=3) x_axis_cross, y_axis_cross, crosses_result_list = find_crosses(image_data) #This step is crucial for further poly interpolation and diagram drawing crosses_result_list.sort(reverse=True, key=lambda x: x[0]) x_list = [point[0] for point in crosses_result_list] y_list = [point[1] for point in crosses_result_list] xp, yp = prepare_poly_interpolated_plot(x_list, y_list, plot_pts_size, f_poly_power) draw_point_plot(draw, xp, yp, plot_pts_size) draw.point((x_axis_cross, y_axis_cross), (255, 0, 0)) for pt in crosses_result_list: draw.point((pt[0], pt[1]), (0, 255, 0))
def apply_apply_gaussian_laplasian_to_image(pix, derivative_kernel, longitude_kernel, width, height, radius = 2, sigma = 1, channels=3, mode="image"): gaussian_laplasian = get_gaussian_laplasian(radius, sigma, derivative_kernel, normalized=True) gaussian_laplasian = convolve2d(longitude_kernel, gaussian_laplasian) if mode == "image": image_data = convert_image_to_data_buffer(pix, width, height, channels, orientation="user-wise") result_data = convolve2d(image_data, gaussian_laplasian, mode='same') elif mode == "buffer": result_data = convolve2d(pix, gaussian_laplasian, mode='same') else: raise ValueError("ERROR: wrong type of image: {} (only 'image' and 'buffer' are possible))".format(mode)) return result_data