예제 #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('input', help='input BMP file name')
    parser.add_argument('output', help='output BMP file name')
    parser.add_argument('--crop', help='crop the specifide area: x1,y1,x2,y2')
    parser.add_argument('--select_color',
                        help='select one color: red,green,blue')
    parser.add_argument('--rotate')

    args = parser.parse_args()

    data = bmp.read_bmp(args.input)

    if args.rotate:
        data = scipy.ndimage.rotate(data, args.rotate, prefilter=False)

    if args.select_color:
        color = args.select_color.lower()[0]  # r, g or b
        data = data * np.array(COLOR_VECTORS[color])

    if args.crop:
        x1, y1, x2, y2 = args.crop.split(',')
        x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
        data = data[y1:y2 + 1, x1:x2 + 1]

    bmp.write_bmp(args.output, data)
예제 #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('input', help="input BMP file name")
    parser.add_argument("output", help ="output BMP file name")
    parser.add_argument("--crop", help="crop to specified are: eg. X1, Y1, X2, Y2")
    parser.add_argument('--select-color', help="select one color: red, green or blue")
    parser.add_argument('--black-and-white', action='store_true')
    parser.add_argument('--rotate', type=int, help="rotate by given number of degree")
    parser.add_argument('--blur', action="store_true")

    args= parser.parse_args()

    data=bmp.read_bmp(args.input)

    if args.blur:
        data = scipy.ndimage.guassian_filter(data,(3,3,0)) #(0,0,1.5)

    if args.select_color:
        color = args.select_color.lower([0]) #r,g or b
        data=data*np.array(COLOR_VECTORS[color])

    if args.crop:
        x1, y1, x2, y2 = args.crop.split(',')
        x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
        data = data[y1:y2+1, x1:x2+1]

    if args.rotate:
        data = scipy.ndimage.rotate(data, args.rotate, prefilter=False)

    bmp.write_bmp(args.output, data)

    data = bmp.read_bmp(args.input)
    bmp.write_bmp(args.output, data)
예제 #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('input', help="input BMP file name")
    parser.add_argument('output', help="output BMP file name")
    parser.add_argument('--crop',
                        help="crop to specified area, eg. X1,Y1,X2,X2")
    parser.add_argument('--select-color',
                        help="select one color: red, green, blue")
    parser.add_argument('--black-and-white', action="store_true")
    parser.add_argument('--blur', action="store_true")
    parser.add_argument('--rotate', type=int, help="rotate by given degrees")
    args = parser.parse_args()

    data = bmp.read_bmp(args.input)

    if args.blur:
        data = scipy.ndimage.gaussian_filter(data, (2, 2, 0))

    if args.rotate:
        data = scipy.ndimage.rotate(data, args.rotate, prefilter=False)

    if args.select_color:
        color = args.select_color.lower()[0]
        data = data * np.array(COLOR_VECTORS[color])

    if args.black_and_white:
        data = data.sum(axis=2, keepdims=True) / 3
        data = np.ones(3) * data

    if args.crop:
        x1, y1, x2, y2 = args.crop.split(',')
        x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
        data = data[y1:y2 + 1, x1:x2 + 1]

    bmp.write_bmp(args.output, data)
예제 #4
0
def main():
    args = parse_args()
    data = bmp.read_bmp(args.input)

    if args.rotate:
        data = ndimage.rotate(data, angle=args.rotate)
    if args.blur:
        data = ndimage.gaussian_filter(data, sigma=3)
    if args.black_white:
        sum_array = data.sum(axis=2, keepdims=True) / 3
        data = np.ones(3) * sum_array
    if args.color:
        data = data * np.array([args.color == 'BLUE', args.color == 'GREEN', args.color == 'RED'])

    bmp.write_bmp(args.output, data)
예제 #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('input', help='input BMP file name')
    parser.add_argument('output', help='output BMP file name')
    parser.add_argument('--crop', help='crop to specified area')
    parser.add_argument('--select-color',
                        help='select one color: red, green, blue')
    parser.add_argument('--black-and-white', action='store_true')
    parser.add_argument('--blur', action='store_true')
    parser.add_argument('--rotate',
                        type=int,
                        help='rotate by given number of degrees')
    args = parser.parse_args()

    data = bmp.read_bmp(args.input)

    if args.blur:
        data = scipy.ndimage.gaussian_filter(data, (6, 1, 1.5))

    if args.rotate:
        data = scipy.ndimage.rotate(data, args.rotate, prefilter=False)

    if args.select_color:
        color = args.select_color.lower()[0]  # r, g or b
        data = data * np.array(COLOR_VECTORS[color])

    if args.black_and_white:
        data = data.sum(axis=2, keepdims=True) / 3
        data = data * np.array([1, 1, 1])

    if args.crop:
        x1, y1, x2, y2 = args.crop.split(',')
        x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
        data = data[y1:y2 + 1, x1:x2 + 1]

    bmp.write_bmp(args.output, data)
예제 #6
0
def cut_out_image(pixel_matrix):
    pixels = pixel_matrix[120:354, 140:430]
    bmp.write_bmp('tiger_cut_out.bmp', pixels)
예제 #7
0
def black_and_white(pixel_matrix):
    # can use also: scipy.ndimage.filters.gaussian_filter (see sigma param)
    sum_array = pixel_matrix.sum(axis=2, keepdims=True) / 3
    bmp.write_bmp('black_and_white_tiger.bmp', np.ones(3) * sum_array)
예제 #8
0
def rotate_image(pixel_matrix, degrees: float):
    bmp.write_bmp(
        'rotated_tiger.bmp',
        scipy.ndimage.interpolation.rotate(pixel_matrix, degrees, order=1))
예제 #9
0
def single_color(pixel_matrix, color_index):
    mask = np.zeros(3)
    mask[color_index] = 1
    bmp.write_bmp('single_color.bmp', pixel_matrix * mask)