How can I make diamond shape with a matrix?

12 vues (au cours des 30 derniers jours)
Coeing
Coeing le 25 Nov 2019
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!!

Réponses (3)

Stephen23
Stephen23 le 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

Andrei Bobrov
Andrei Bobrov le 25 Nov 2019
Modifié(e) : Andrei Bobrov le 26 Nov 2019
a = strel('diamond',250);
out = kron(a.Neighborhood,[1 2 ; 3 4]);

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

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by