
findで特定した位置の個所にあるピクセルを拡張したいです。
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
有那 小泉
am 26 Nov. 2020
Beantwortet: Akira Agata
am 28 Nov. 2020
閲覧ありがとうございます。
matlab R2020b(Windows)を使っております。
2値化した画像内の一つのピクセルの回りに0がいくつあるかの計算を以下の方法で行い、カラーマップを作成しました。
I = imread('sen.jpg'); %画像読み込み
BW = imbinarize(rgb2gray(I)); %2値化
BW2 = imcomplement(BW); %色反転
% 各ピクセルについて、自身を含む周囲 3×3 領域内の 0 の数を数える
H = filter2(ones(3),~BW2);
% 表示のためのカラーマップを準備
cMap = jet(10);
% 結果を表示
figure
imagesc(H,[-0.5 9.5])
colormap(cMap)
colorbar
カラーマップ内の7の数値の個所を膨張させるためにfindを使い7の数値の個所は特定出来たのですが、このまま膨張させようとするとその個所の数字が膨張してしまうようです。(説明が難しいです)
そのコードが以下になります。
Hpos=find(H==7);
c = BW2(Hpos);
se = strel('square',2);
BW3 = imdilate(c,se);%多分ここで詰まっている
K = imcomplement(BW3); %色反転
imshow(K),
解決方法が分かる方、お願い致します。
0 Kommentare
Akzeptierte Antwort
Akira Agata
am 28 Nov. 2020
以前ご質問頂いた内容のつづきと想定して、以下のような処理でしょうか?
I = imread('image.jpeg'); % 画像読み込み
BW = imbinarize(rgb2gray(I)); % 2値化
BW = ~BW; % 白黒反転
H = filter2(ones(3),~BW);
BWext = H == 7;
se = strel('square',2);
BWext2 = imdilate(BWext, se); % 値が7のピクセルを膨張
BWout = BW | BWext2; % 元の2値画像とマージ
cMap = jet(10);
% 結果を表示
tiledlayout('flow')
nexttile
imshow(BW)
title('[1] 元のバイナリ画像','FontSize',12)
ax = nexttile;
imagesc(H,[-0.5 9.5])
colormap(ax,cMap)
colorbar
axis tight
axis equal
title('[2] 近傍の1の個数','FontSize',12)
nexttile
imshow(BWext)
title('[3] 値が7のピクセル','FontSize',12)
nexttile
imshow(BWext2)
title('[4] [3]を膨張','FontSize',12)
nexttile
imshow(BWout)
title('[5] 元画像とマージ([1]+[4])','FontSize',12)

0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu White finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!