How can I make diamond shape with a matrix?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to make diamond image with a matrix
ex. background image is zeros(1000,1000)
from center, make this matrix [1 2 ; 3 4] like a diamond..
.
.
.
0 0 1 2 0 0...
0 0 3 4 0 0
1 2 1 2 1 2
3 4 3 4 3 4
0 0 1 2 0 0
0 0 3 4 0 0 ...
.
.
.
plz help me.. thanks!!
0 Kommentare
Antworten (3)
Stephen23
am 26 Nov. 2019
Without the image toolbox:
>> N = 5;
>> V = round((N:-1:1)/(N+1));
>> M = toeplitz(V);
>> M = M & rot90(M)
M =
0 0 1 0 0
0 1 1 1 0
1 1 1 1 1
0 1 1 1 0
0 0 1 0 0
>> kron(M,[1,2;3,4])
ans =
0 0 0 0 1 2 0 0 0 0
0 0 0 0 3 4 0 0 0 0
0 0 1 2 1 2 1 2 0 0
0 0 3 4 3 4 3 4 0 0
1 2 1 2 1 2 1 2 1 2
3 4 3 4 3 4 3 4 3 4
0 0 1 2 1 2 1 2 0 0
0 0 3 4 3 4 3 4 0 0
0 0 0 0 1 2 0 0 0 0
0 0 0 0 3 4 0 0 0 0
0 Kommentare
Andrei Bobrov
am 25 Nov. 2019
Bearbeitet: Andrei Bobrov
am 26 Nov. 2019
a = strel('diamond',250);
out = kron(a.Neighborhood,[1 2 ; 3 4]);
Akira Agata
am 26 Nov. 2019
How about the following?
N = 5; % <- Should be odd number
A = repmat([1 2;3 4],N);
se = strel('diamond',floor(N/2));
idx = imresize(se.Neighborhood,2);
A(~idx) = 0;
>> A
A =
0 0 0 0 1 2 0 0 0 0
0 0 0 0 3 4 0 0 0 0
0 0 1 2 1 2 1 2 0 0
0 0 3 4 3 4 3 4 0 0
1 2 1 2 1 2 1 2 1 2
3 4 3 4 3 4 3 4 3 4
0 0 1 2 1 2 1 2 0 0
0 0 3 4 3 4 3 4 0 0
0 0 0 0 1 2 0 0 0 0
0 0 0 0 3 4 0 0 0 0
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Data Workflows 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!