Randomizing Color to 3D Objects - improving speed
Ältere Kommentare anzeigen
Hi all,
I have a 3D array with spheres embedded in the array, labeled as 1, and 0 elsewhere. I want to count the spheres and then randomize color with each sphere so when I look at an arbitrary 2D slice through the 3D array, I can verify that each sphere was uniquely identified. (i.e. if two spheres were close together and were considered the same sphere, they would be the same color). Anyways I've completed the task in a simple manner (see below) and my question pertains to how to make this operation faster. Any and all help will be greatly appreciated. Thank you.
if true
% code
SphereLabel=bwlabeln(SphereBW,26);
AddMatrix = zeros(512,512,256,'uint8');
hWaitBar=waitbar(0,'Randomizing');
for i = 1:max(SphereLabel(:))
f1=round(rand(1)*255);
AddMatrix(SphereLabel==i)=f1;
waitbar(i/max(X(:)))
end
delete(hWaitBar)
AddMatrix(:,:,:,2) = AddMatrix(:,:,:,1);
AddMatrix(:,:,:,3) = AddMatrix(:,:,:,1);
end
If there is a large number of spheres in the matrix, then this will take a long time. I'm not sure if there is a faster way, but I thought I'd ask if anyone had any suggestions to improve the speed of this. Always appreciate it.
Cheers, Edwin
Akzeptierte Antwort
Weitere Antworten (1)
Edwin
am 20 Nov. 2014
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!