画像をパディングし正方形にする方法

14 vues (au cours des 30 derniers jours)
拓 青柳
拓 青柳 le 5 Oct 2022
Commenté : 拓 青柳 le 19 Oct 2022
深層学習によるX線画像の二値分類を行なっております。
様々なサイズのX線画像があり、全ての画像を長径の長さの正方形にゼロパディングした後、224×224に縮小したいです。
何か方法はありますでしょうか。

Réponse acceptée

Akira Agata
Akira Agata le 6 Oct 2022
Modifié(e) : Akira Agata le 6 Oct 2022
関数 padarray を使って、以下のようにする方法はいかがでしょうか?
% サンプル画像 (1000×200ピクセル)
I_in = randi(255, [1000 200], "uint8");
% 縦横のピクセル数とその差を取得
sz = size(I_in);
d = abs(diff(sz));
% 縦横のうち短いほうに対して、両側に d/2 だけゼロパディング(※)
if sz(1) < sz(2)
I_pad = padarray(I_in, [round(d/2), 0], 0, "both");
else
I_pad = padarray(I_in, [0, round(d/2)], 0, "both");
end
% 全体を 224×224 にリサイズ
I_out = imresize(I_pad, [224, 224]);
※厳密には、縦横のピクセル数の差が奇数の場合にはどちらか片側のパディング幅を round(d/2)-1 にする必要があります。
  1 commentaire
拓 青柳
拓 青柳 le 19 Oct 2022
上手くいきました!
ありがとうございます。

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur イメージを使用した深層学習 dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!