From: Anna on 7 May 2010 18:46 Hello, I have a simple problem which I am hoping to find a simple solution for. I have a binary volume where elements that represent the object are 1 and the background is 0. I would like to extract the TOP surface of the object. For example, if the object was a solid sphere, I would want to extract the surface of the topmost hemisphere. I have previously achieved this by having nested for loops which search each line of each slice of the volume and make the first '1' element encountered '1' in the corresponding voxel in a new empty volume then exiting the for loop. See below for the code. This is a messy, slow way of achieving my surface extraction so I was hoping to find a better way. My idea to solve this is as follows: 1. find the subscript of each 'object' pixel ind = find(img); [X,Y,Z] = ind2sub(size,ind); 2. For each x,z combination, find the max y and make that subscript '1' in a new empty volume. I am unsure how to achieve step 2, if it is at all possible, because I am not completely familiar with all of matlab's functions. Does anyone have a suggestion for me? Thank you very much for your help. The old code is: newVOL= 0.*oldVOL; for n = 1:size(oldVOL) %n temp = oldVOL(:,:,n); for n_1 = 1:size(temp,1) for n_2 = size(temp,2):-1:1 if temp(n_1,n_2) == 255 for nn = 0:0 newVOL(n_1,n_2,n+nn) = 255; end break; end end end end (ugly, huh?)
From: ImageAnalyst on 7 May 2010 19:14 Define "Top" because your code does not seem to just find the topmost surface. It will also find outer layers in the x,y plane even though those layers are basically undercut of the larger layers above. For example, if your binary volume is an umbrella, your code will find the surface of the umbrella and the shaft (handle) and not just the top round, dome surface. You also seem to have no way of "filling" in discontinuities such as making a disk along the bottom of the umbrella's dome to connect the outer perimeter to the shaft. And those are just two definitions for surface. You could say that for any cube of 3 by 3 by 3 pixels if the center pixel has any of its 26 neighbors with a value of 0, then the center pixel is exposed to the background, and thus it's an outer surface layer. If you wanted to use that definition, then the function convn() is the way to go. Just scan the volume with a kernel of ones(3,3,3) and then threshold the result at 25 or below since you'll only have 26 if the center cube (pixel) is completely surrounded by 26 other 1 pixels and thus it's not a surface pixel. If the value is 25 or less, at least one pixel that it's surrounded with is 0 and so it's touching the background and thus it's a surface pixel.
From: Anna on 9 May 2010 15:32 Thank you very much for your detailed reply. I suppose I should make a few clarifications. "Top" is arbritrary; it can be the side, the bottom, at an angle, it doesn't matter. Also, discontinuities do not matter. To illustrate my task a bit better: In ultrasound imaging, bone produces a shadow beneath itself, so you can only see the "top" surface. This means that there will be discontinuities and odd forms (like the shaft in your umbrella example). Now say I have a simulated binary volume which contains a "bone". I want to pretend the ultrasound probe is coming from one side (the "top") extract the "bones" surface just as an ultrasound probe would do. The code I have posted previously provides the results that I want, it is just poorly written. Thanks for your help. ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <1c33954e-47a1-422b-a194-159cdf478476(a)q30g2000yqd.googlegroups.com>... > Define "Top" because your code does not seem to just find the topmost > surface. It will also find outer layers in the x,y plane even though > those layers are basically undercut of the larger layers above. For > example, if your binary volume is an umbrella, your code will find the > surface of the umbrella and the shaft (handle) and not just the top > round, dome surface. You also seem to have no way of "filling" in > discontinuities such as making a disk along the bottom of the > umbrella's dome to connect the outer perimeter to the shaft. > > And those are just two definitions for surface. You could say that > for any cube of 3 by 3 by 3 pixels if the center pixel has any of its > 26 neighbors with a value of 0, then the center pixel is exposed to > the background, and thus it's an outer surface layer. If you wanted > to use that definition, then the function convn() is the way to go. > Just scan the volume with a kernel of ones(3,3,3) and then threshold > the result at 25 or below since you'll only have 26 if the center cube > (pixel) is completely surrounded by 26 other 1 pixels and thus it's > not a surface pixel. If the value is 25 or less, at least one pixel > that it's surrounded with is 0 and so it's touching the background and > thus it's a surface pixel.
From: ImageAnalyst on 9 May 2010 15:39 You're welcome. Well, as long as it's doing what you want, great!
|
Pages: 1 Prev: remove black bar outline in bar3 Next: Mixed Integer Nonlinear Optimization |