- Is there just 1 pattern of 1s within the matrix or several disconnected patterns of 1s?
- How should the pattern be expanded/contracted?
- Does the matrix of 0s change size, too? If not, what happens when the 1s become larger than the 0s?
- Factors are usually multiplicative. Is the factor always a positive integer? If not, how should we treat rounding?
How to resize a group of ones in an array of zeros?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
If i have an array of zeors (512,512) with a couple of ones in there making up a shape, how do i rezise that group of ones making that shape either smaller or larger by a inputted factor
ex
0 0 0 0 0
0 1 1 1 0
0 0 1 1 0
0 0 0 0 0
0 0 0 0 0
i though of doing a for loop changing (i,j+1), (i,j-1),(i+1,j),(i-1,j) to a value of one for (1: the number inputted to resize). However the problem with this is that this doesnt correctly resize the ones image, for an example, inputting a 2 doesnt result in a doubled image. Also this doesnt work to decrease the size of the ones image.
3 commentaires
Adam Danz
le 23 Sep 2019
That's a little better but it's still not clear how you'd like to expand/decrease the shape.
Again, a few (more than 1) input & expected output pairs (with much smaller matrices) would be more grounded and would leave less of the burdon of interpretation up to us. Two volunteers have already invested time into answers that won't work because the question was unclear. It would be unwise to invest more time without a clear definition of how the expansion/contraction would work.
Réponses (2)
KALYAN ACHARJYA
le 23 Sep 2019
Modifié(e) : KALYAN ACHARJYA
le 23 Sep 2019
If i have an array of zeors (512,512) with a couple of ones in there making up a shape, how do i rezise that group of ones making that shape either smaller or larger by a inputted factor
data=[0 0 0 0 0
0 1 1 1 0
0 0 1 1 0
0 0 0 0 0
0 0 0 0 0]
result=imresize(data,2)
%....................^ times larger, here double
Command Window:
data =
0 0 0 0 0
0 1 1 1 0
0 0 1 1 0
0 0 0 0 0
0 0 0 0 0
result =
0.0088 -0.0190 -0.0747 -0.1003 -0.0959 -0.0959 -0.1003 -0.0747 -0.0190 0.0088
-0.0212 0.0466 0.1822 0.2377 0.2132 0.2062 0.2169 0.1619 0.0413 -0.0190
-0.0813 0.1778 0.6960 0.9139 0.8315 0.8106 0.8513 0.6350 0.1619 -0.0747
-0.0813 0.1708 0.6751 0.9742 1.0681 1.1353 1.1760 0.8716 0.2222 -0.1025
-0.0212 0.0257 0.1196 0.4186 0.9229 1.1804 1.1910 0.8716 0.2222 -0.1025
0.0066 -0.0346 -0.1170 0.1009 0.6191 0.8765 0.8732 0.6350 0.1619 -0.0747
0.0022 -0.0101 -0.0346 0.0209 0.1566 0.2238 0.2227 0.1619 0.0413 -0.0190
0 0.0016 0.0049 -0.0143 -0.0560 -0.0769 -0.0769 -0.0560 -0.0143 0.0066
0 0.0005 0.0016 -0.0048 -0.0187 -0.0256 -0.0256 -0.0187 -0.0048 0.0022
0 0 0 0 0 0 0 0 0 0
0 commentaires
Adam Danz
le 23 Sep 2019
Modifié(e) : Adam Danz
le 23 Sep 2019
Maybe interp2() would help.
% Input data
m = [0 0 0 0 0
0 1 1 1 0
0 0 1 1 0
0 0 0 0 0
0 0 0 0 0];
% Interpolate
mInt = double(interp2(m,1) > 0);
% ^ this value (k) determines interp resolution.
% There will be 2^k-1 number of data points added
% between each sample.
% compare original vs interp'd
figure()
subplot(1,2,1)
heatmap(m)
title('Original data')
subplot(1,2,2)
heatmap(mInt)
title('Interp''d data')

0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!