create 3*3 matrix around a given pixel

1 回表示 (過去 30 日間)
Yuvashree Mani Urmila
Yuvashree Mani Urmila 2014 年 7 月 7 日
回答済み: Mahendra Amrao 2020 年 9 月 8 日
I have a centroid plotted on a blank image using the command img(a(2),a(1))=1;
I would like to create a 3*3 matrix of ones around this pixel as centroid.
Can someone tell me how i can achieve this.
Thankyou

採用された回答

Jos (10584)
Jos (10584) 2014 年 7 月 7 日
One solution:
img = zeros(6,7)
a = [4 3]
img(a(2),a(1)) = 1
B = [1 1 1 ; 1 0 1 ; 1 1 1];
img2 = conv2(img, B ,'same')

その他の回答 (1 件)

Mahendra Amrao
Mahendra Amrao 2020 年 9 月 8 日
img = zeros(6,7)
a = [4 3]
img(a(2),a(1)) = 1
B = [1 1 1 ; 1 0 1 ; 1 1 1];
img2 = conv2(img, B ,'same')

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by