物理の駅 Physics station by 現役研究者

テクノロジーは共有されてこそ栄える

16bitモノクロ画像を8bitモノクロ画像に変換するコード

16bitモノクロ画像の輝度値の最小が3802、最大が11113とする。

import numpy as np
import cv2
src= cv2.imread("input.tif",-1)
src=np.add(src, -3802)
src=src*(255/(11113-3802))
dst = src.astype(np.uint8)
cv2.imwrite("output.png",dst)

注意点:

imread の引数を0 又は 1にすると、8bit モノクロ画像 又は 8bit カラー画像として読み込まれてしまう。-1だと画像のbit深度、チャンネル数は変更されない。

C++版だとcv::convertTo関数だが、python版だと型変換は numpyのastype(np.uint8) で行う。

mp4 (動画ファイル)からmp3等の音声ファイルを抽出(分離)するWindows用ソフト

www.vector.co.jp

Flush全盛期の時代に、flvファイル→音声ファイル をやってた人には馴染みのあるソフト。mp4等の動画ファイルにも対応している。ドラッグ&ドロップだけで作業は完了し、exeの直下に動画のファイル名でフォルダが作成され、その中に SOUND フォルダと VIDEO フォルダができる。機能は抽出だけで、統合はできない。

m4aは、Windows版のiTunesでmp3に変換できる。

最近はもっと高機能なソフトがあるんだろうけど、こういう古いが単機能で広告もないソフトって、最近はGoogle検索でヒットしないんだよね。

READMEから引用

■出力形式
    PCM(WAVE)データ
    ADPCMデータ (PCMにデコードして出力)
    Nellymoserデータ(PCMにデコードして出力)
    Speexデータ(PCMにデコードして出力)
    MP3データ
    AACデータ(M4A/MP3/PCMなどで出力)
    BMPデータ
    JPEGデータ
    PNGデータ
    GIFデータ
    SorensonH.263ビデオデータ (AVI形式で出力)
    ScreenVideo(V2未対応)データ (AVI形式で出力)
    On2VP6ビデオデータ (AVI形式で出力)
    H264/AVCビデオデータ (MP4/AVIなどで出力)
    ActionScript、その他

■入力対象
    SWF(フラッシュファイル)
    FLV(フラッシュビデオ)
    F4V/MP4(H264/AVC)
    EXE(フラッシュベースのWindows用プロジェクタファイル)
    SCR(スクリーンセーバーファイル)
    その他

PythonでWikipediaに登場するひらがなの数を数えてみる

Wikiediaには、ランダムなページに飛んでくれるSpecialなURLがある。

https://ja.wikipedia.org/wiki/Special:Randompage

これを使って、適当なページに存在するひらがなの数を数えてみる。

import matplotlib.pyplot as plt
import urllib.request

n_pages = 10
# ラムダムなページをダウンロードし、ファイルに保存
url = "https://ja.wikipedia.org/wiki/Special:Randompage"
for i in range(n_pages):
    urllib.request.urlretrieve(url, "{0:05d}.txt".format(i))

# ひらがなリスト
hira_lists = [chr(i) for i in range(12353, 12436)]

hira_counter = {}
# ひらがなの数のカウンターを初期化
for hira in hira_lists:
    hira_counter[hira] = 0

# Wikipediaのページを読み込み、ひらがなの数を数える
for i in range(n_pages):
    with open("{0:05d}.txt".format(i), encoding="utf-8") as f:
        text = f.read()
        for hira in hira_lists:
            hira_counter[hira] += text.count(hira)

# カウンター内を表示
print(hira_counter)

moji = [key for key in hira_counter.keys()]
kazu = [value for value in hira_counter.values()]
print(moji, kazu)
plt.plot(moji, kazu)
plt.show()

結果

f:id:onsanai:20200707141516p:plain

「の」が一番多い。

Linuxコマンド iostat -x で出力される各項目とその意味(日本語意訳)

ドキュメントの英語の原文と、筆者による日本語の意訳

sebastien.godard.pagesperso-orange.fr

r/s
完了した読み取りリクエスト数/s
The number (after merges) of read requests completed per second for the device. 

w/s
完了した書き込みリクエスト数/s
The number (after merges) of write requests completed per second for the device.

rsec/s (rkB/s, rMB/s)
デバイスから読み込まれるセクタ数[KB/s]
The number of sectors (kilobytes, megabytes) read from the device per second. 

wsec/s (wkB/s, wMB/s)
デバイスに書き込まれるセクタ数[KB/s]
The number of sectors (kilobytes, megabytes) written to the device per second.

rrqm/s
キューに入ってマージされた読み取り要求数/s
The number of read requests merged per second that were queued to the device. 

wrqm/s
キューに入ってマージされた書き込み要求数/s
The number of write requests merged per second that were queued to the device.

%rrqm
デバイス送信前にマージされた読み取り要求率[%]
The percentage of read requests merged together before being sent to the device.

%wrqm
書き込み要求がデバイス送信前にマージされた率[%]
The percentage of write requests merged together before being sent to the device.

r_await
読み取り要求平均時間[ms]
The average time (in milliseconds) for read requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.

w_await
書き込み処理平均時間[ms]
The average time (in milliseconds) for write requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.

aqu-sz
リクエストの平均キュー長
The average queue length of the requests that were issued to the device.
Note: In previous versions, this field was known as avgqu-sz.

%util
デバイスの帯域幅の使用率 (RAIDやSSDの場合は意味合いが違うかも)
Percentage of elapsed time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs when this value is close to 100% for devices serving requests serially. But for devices serving requests in parallel, such as RAID arrays and modern SSDs, this number does not reflect their performance limits.