def main():
    # Just a test that things are ready and working for dynamic programming
    # Visualize vertical map

    black_pixels = find_black_pixels(image)
    vertical_map = get_vertical_map(black_pixels, image)

    v = viewer.ImageViewer(image)
    v.show()

    weight_function = partial(dynamic_weight, black_pixels, vertical_map)
    weights = np.zeros((img_height, img_width), dtype = np.uint64)

    # Visualize global weights
    for (y, x) in itertools.product(range(img_height), range(img_width)):
        weights[y, x] = weight_function((y, x))

    v = viewer.ImageViewer(weights / float(np.max(weights)))
    v.show()

    # Bound image to first staff line and calculate weights for the area
    # Weights out of bounds (inclusive of border!) are set high
    for (y, x) in itertools.product(range(img_height), range(img_width)):
        if (not y_top + 1 <= y < y_bot or not x_left + 1 <= x < x_right):
            weights [y,x] += 10000
        else:
            weights[y, x] = weight_function((y, x))

    # Normalized with the boundary weights; should just be a black rectangle
    v = viewer.ImageViewer(weights / float(np.max(weights)))
    v.show()
def display_contours():
    """pick an image, resize for easy computation, display original vs contour"""
    my_file = easygui.fileopenbox(default=os.getcwd(),
                                  filetypes=["*.png", "*.jpg"])

    assert my_file.endswith(".png") or my_file.endswith(
        ".jpg"), "please select a .jpg or .png image file"

    my_img = io.imread(my_file, as_gray=True)

    x_size, y_size = my_img.shape
    size = x_size * y_size
    goal_size = 300**2  # chosen so computations run in ~1s
    scaling_factor = (goal_size / size)**(0.5)

    my_img = resize(
        my_img,
        (math.floor(
            x_size * scaling_factor), math.floor(y_size * scaling_factor)),
        anti_aliasing=True,
    )

    overall_grad_img = exposure.equalize_hist(produce_overall_grad(my_img))

    output_img = np.empty(my_img.shape)

    for column in range(0, len(overall_grad_img)):
        for value in range(0, len(overall_grad_img[column])):
            output_img[column, value] = 1 - overall_grad_img[column, value]

    final_output = np.concatenate([my_img, output_img], axis=1)
    viewer.ImageViewer(final_output).show()
Beispiel #3
0
def show_image(image):
    """Displays image on screen with matplotlib-based canvas.

    :param image: Image data
    :return: image viewer object
    """

    display_image = viewer.ImageViewer(image)
    display_image.show()
    return display_image
Beispiel #4
0
filter_relativ_height_sidewalk[(isnan(filter_relativ_height_sidewalk)==False)]
imshow(filter_relativ_height_sidewalk, cmap=plt.cm.gray) ; plt.show();

Z_around_sidewalk = Z * filter_relativ_height_sidewalk ; 
imshow(Z_around_sidewalk, cmap=plt.cm.gray) ;
#Z_around_sidewalk[Z_around_sidewalk!=0]
#new_viewer = viewer.ImageViewer(Z_around_sidewalk) ; new_viewer.show() ; 
tmp_min = np.min(Z_around_sidewalk[isnan(Z_around_sidewalk)==False]) ;
tmp_max = np.max(Z_around_sidewalk[isnan(Z_around_sidewalk)==False]) ;
Z_around_sidewalk= (Z_around_sidewalk - (tmp_max+tmp_min)/2 ) / (tmp_max-tmp_min)  ;

convert_to_float = img_as_float(filter_relativ_height_sidewalk) 
convert_to_float[isnan(convert_to_float)==False]

convert_to_int = img_as_int(Z_around_sidewalk) ; 
viewer.ImageViewer(convert_to_int).show() ; 
grad =  gradient(convert_to_int,disk(1)) ;
sobel_result = sobel(convert_to_int,sidewalk_mask) 
viewer.ImageViewer(sobel_result).show()

new_viewer = viewer.ImageViewer(grad) 
new_viewer += lineprofile.LineProfile()
new_viewer.show()

imshow(grad, cmap=plt.cm.gray); plt.show();


 
from skimage.morphology import disk
from skimage.filter.rank import gradient
  
Beispiel #5
0
### Load and plot image ###

# set the image file name
img_file = 'image.jpg'

# load the image as grayscale in one step
img = io.imread(img_file, as_gray=True)
# alternatively, you can load the original image and then convert it to grayscale
# img2 = io.imread(img_file)
# img2 = color.rgb2gray(img2)

print('image matrix size: {}'.format(img.shape))  # print the size of image
print('First 5 columns and rows of the image matrix:\n {}'.format(img[:5, :5] *
                                                                  255))
viewer.ImageViewer(img).show()  # plot the image

### Convolve the sharpen kernel with an image ###

# Adjust the contrast of the image by applying Histogram Equalization
# clip_limit: normalized between 0 and 1 (higher values give more contrast)
image_equalized = exposure.equalize_adapthist(img / np.max(np.abs(img)),
                                              clip_limit=0.03)
plt.imshow(image_equalized, cmap=plt.cm.gray)
plt.axis('off')
plt.show()

# Convolve the sharpen kernel and the image
kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]])
image_sharpen = convolve2d(img, kernel)
print('First 5 columns and rows of the image_sharpen matrix:\n {}'.format(
    image_padded = np.zeros((image.shape[0] + 2, image.shape[1] + 2))
    image_padded[1:-1, 1:-1] = image

    for m in range(image.shape[1]):
        for n in range(image.shape[0]):
            # element-wise multiplication of the kernel and the image
            # and then add up the multiplications
            output[n, m] = (kernel*image_padded[n:n+3, m:m+3]).sum()

    return output


img = io.imread('toronto-skyline.jpg', as_gray=True)  # load image as grayscale
print('image matrix size: ', img.shape)  # print the size of the image
print('\n First 5 columns and rows of the image matrix: \n', img[:5, :5]*255)
viewer.ImageViewer(img).show()  # plot the image


# Convolve the image with a filter that blurs the image...
blur_filter = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]])/9.0
edge_filter = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])
sharpen_filter = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]])

random.seed()
rand_num = random.random()
random_filter = np.array([[7, 9, 23],
                          [76, 91, 7],
                          [64, 90, 32]])/255

# image_sharpen = convolve2d(img, sharpen_filter);
image_sharpen = scipy.signal.convolve2d(img, random_filter, 'same')
Beispiel #7
0
            if mask[y][x][m] == False:
                image2[y][x] = [0,0,0]#黒にする#何とか透過させたい
            """

    """
    cv2.imwrite("output1.png",image2)
    cv2.imshow("procecced",image2)
    

    cv2.waitKey(0)
    cv2.destroyAllWindows()
    """
    #plt.imshow(image2)
    #plt.show()
    from skimage import viewer
    new_viewer = viewer.ImageViewer(image2) 
    new_viewer.show() 
    










    

Beispiel #8
0
           
           
#####
import skimage.io as io
from skimage import data_dir
coll = io.ImageCollection(data_dir + '/chess*.png')
len(coll)
coll[0].shape
ic = io.ImageCollection('/tmp/work/*.png:/tmp/other/*.jpg')

#############

from skimage import viewer
coins = data.coins()

new_viewer = viewer.ImageViewer(coins) 
new_viewer.show()

new_viewer = viewer.ImageViewer(coins) 
from skimage.viewer.plugins import lineprofile
new_viewer += lineprofile.LineProfile() 
new_viewer.show() 

check = np.zeros((9, 9))
check[::2, 1::2] = 1
check[1::2, ::2] = 1
plt.matshow(check, cmap='gray')
plt.show()

from skimage import exposure
camera = data.camera()