create 3*3 matrix around a given pixel

조회 수: 11 (최근 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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by