Ejemplo n.º 1
0
def main(args):
    for name in args.dot:
        # dot言語で記述されたファイルを読み込む
        (graph, ) = pydot.graph_from_dot_file(name)
        # 保存用の名前を抽出する
        name, _ = os.path.splitext(os.path.basename(name))
        # 形式を選択して保存する
        if (args.ext == 'png'):
            graph.write_png(getFilePath(args.out_path, name, '.png'))
        elif (args.ext == 'pdf'):
            graph.write_pdf(getFilePath(args.out_path, name, '.pdf'))
        elif (args.ext == 'svg'):
            graph.write_svg(getFilePath(args.out_path, name, '.svg'))
        else:
            print('[ERROR] ext option miss:', args.ext)
Ejemplo n.º 2
0
def main(args):
    # NPZ形式のファイルを読み込む
    np_arr = np.load(args.npz)
    x = IMG.arr2imgs(np_arr['x'])
    y = IMG.arr2imgs(np_arr['y'])
    ch = 3
    if (x.shape[ch] > y.shape[ch]):
        y = [cv2.cvtColor(i, cv2.COLOR_GRAY2RGB) for i in y]
        y = np.array(y)

    if (x.shape[ch] > y.shape[ch]):
        x = [cv2.cvtColor(i, cv2.COLOR_GRAY2RGB) for i in x]
        x = np.array(x)

    # 全てを画像化するのは無駄なのでランダムに抽出する
    if (args.random_seed >= 0):
        np.random.seed(args.random_seed)

    shuffle = np.random.permutation(range(len(x)))
    # ランダムに抽出した画像を結合する
    # 上半分にはxの画像をimg_numの数だけ
    # 下半分にはyの画像をimg_numの数だけ結合した画像を作成する
    img = np.vstack((np.hstack(x[shuffle[:args.img_num]]),
                     np.hstack(y[shuffle[:args.img_num]])))
    # そのままのサイズでは画像が小さいので、拡大する
    size = (int(img.shape[1] * args.img_rate),
            int(img.shape[0] * args.img_rate))
    img = cv2.resize(img, size, cv2.INTER_NEAREST)
    # 作成した画像を表示・保存する
    cv2.imshow('test', img)
    cv2.waitKey(0)
    cv2.imwrite(getFilePath(args.out_path, 'npz2jpg', '.jpg'), img)
Ejemplo n.º 3
0
def main(args):
    imgs = I.io.readN(args.image, args.channel)
    #text = ['[hitotsume]', '[futatsume]', '[mittsume]']
    img = concat3Images(imgs, args.offset, args.img_width, args.channel,
                        args.img_rate)

    cv2.imshow('test', img)
    cv2.waitKey()
    cv2.imwrite(getFilePath(args.out_path, 'concat', '.jpg'), img)
Ejemplo n.º 4
0
def main(args):
    ch = IMG.getCh(args.channel)
    imgs = [cv2.imread(name, ch) for name in args.image]
    #text = ['[hitotsume]', '[futatsume]', '[mittsume]']
    img = concat3Images(imgs, args.offset, args.img_width, args.channel,
                        args.img_rate)

    cv2.imshow('test', img)
    cv2.waitKey()
    cv2.imwrite(getFilePath(args.out_path, 'concat', '.jpg'), img)
Ejemplo n.º 5
0
def savePNG(plt, loc, name, dpi=200):
    """
    png形式での保存を自動化
    [in] plt:  pltオブジェクト
    [in] loc:  ラベルの位置
    [in] name: 保存するファイル名
    [in] dpi:  保存時の解像度
    """

    plt.legend(loc=loc)
    plt.savefig(getFilePath(args.out_path, name, '.png'), dpi=dpi)
Ejemplo n.º 6
0
def write(folder, name, img, ext='.jpg'):
    """
    画像に逐次連番を追加して保存する
    [in]  folder: 保存するフォルダ
    [in]  name:   保存するファイル名
    [in]  img:    保存する画像
    [in]  ext:    拡張子
    [out] path:   保存するファイルのパス
    """

    logger.debug('write({},{},{},{})'.format(folder, name, img.shape, ext))
    write.__dict__.setdefault('count', 0)
    path = getFilePath(folder, name + str(write.count).zfill(4), ext)
    cv2.imwrite(path, img)
    write.count += 1
    logger.debug('\t count: {}'.format(write.count))
    return path
Ejemplo n.º 7
0
def main(args):
    # 画像を読み込む
    imgs = [cv2.imread(name) for name in args.jpeg if IMG.isImgPath(name)]
    # concatするためにすべての画像の高さを統一する
    h = np.max([img.shape[0] for img in imgs])
    imgs = [IMG.resize(img, h / img.shape[0]) for img in imgs]
    # concatするためにすべての画像の幅を統一する
    flg = cv2.BORDER_REFLECT_101
    w = np.max([img.shape[1] for img in imgs])
    imgs = [makeBorder(img, 0, 0, 0, w - img.shape[1], flg) for img in imgs]
    # 画像に黒縁を追加する
    flg = cv2.BORDER_CONSTANT
    lw = args.line_width
    imgs = [makeBorder(img, 0, lw, 0, lw, flg, (0, 0, 0)) for img in imgs]
    # 縦横に連結するための画像リストと縦横情報を取得する
    imgs, size = stackImgAndShape(imgs, args.row)
    # 画像を連結してリサイズする
    buf = [np.vstack(imgs[s]) for s in size]
    img = IMG.resize(np.hstack(buf), args.resize)
    # 連結された画像を保存する
    name = F.getFilePath(args.out_path, 'concat', '.jpg')
    print('save:', name)
    cv2.imwrite(name, img)
Ejemplo n.º 8
0
def write(folder, name, img, ext='.jpg'):
    write.__dict__.setdefault('count', 0)
    path = getFilePath(folder, name+str(write.count).zfill(4), ext)
    cv2.imwrite(path, img)
    write.count += 1