findで特定した位​置の個所にあるピクセ​ルを拡張したいです。

4 vues (au cours des 30 derniers jours)
有那 小泉
有那 小泉 le 26 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),
解決方法が分かる方、お願い致します。

Réponse acceptée

Akira Agata
Akira Agata le 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)

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!