I was wondering if this code could be vectorized, and if so, can it be done without conditionals or loops? It would be great if the vectorized form could be written out so that I could run and follow
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
height = 666;
tri = ones(height);
start= length(tri) + 1;
for column = 1:length(tri)
tri(start:end, column)=0;
if column < (length(tri)/2)
*** no more help needed
0 Commenti
Risposte (2)
Bjorn Gustavsson
il 6 Lug 2020
Sure, you could generate 2 coordinate matrices x and y with meshgrid:
nPix = 66;
[x,y] = meshgrid(1:nPix);
Then you'll have two boundary-lines separating the high and low-level images, in order to set those you can do things like this:
Im = (1 - double(y<2*x))/2; % this is just for one of the boundaries but you can add that condition
And then add the random noise:
Im = Im + 0.5*rand(size(Im));
HTH
darova
il 6 Lug 2020
- use impoly to create triangle region
tri = ones(height);
imshow(tri)
p = impoly(gca,[0 1; 1/2 0; 1 1]*height);
tri1 = p.createMask;
imshow(tri1)
- second part of the code can be simplified
xmas = zeros(height);
xmas = abs(tri1 - noi);
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!