MATLAB Answers

Can strel / morh tools execute a custom operation on the kernel ?

2 views (last 30 days)
Wannabegeek on 14 Jul 2012
Hi all,
I'd like to walk the perimeter of my 3D image in 2D xy planes.
I want my kernel to threshold the edge. So if kernel is say 4x4 pixels, then I want a rule, "any pixel < 0.5 = 0", where the image values are normalized to one.
This would save me a lot of time, rather than having to write code to do this myself.
TIA, wbg

Answers (1)

Image Analyst
Image Analyst on 14 Jul 2012
I don't know what you're saying. What does "walk the perimeter" mean? Why not just call bwboundaries on each 2D slice of your 3D image? And why are you using a kernel with an even number of pixels instead of an odd number? What are your pixel values? Are they in the 0-1 range? It appears that you don't have a uint8 image with pixels in the 0-255 range or even a 16 bit integer image.
I really don't know what this means: "any pixel < 0.5 = 0", where the image values are normalized to one.
But to set any pixel with a value less than 0.5 to 0 you do this:
array3D(array3D<0.5) = 0;
That will not change the class of the image. If it's a double, it will still be a double, not a binary (logical) image. If you want to normalize the image you can use regular scaling formulas, or try im2double(). But your "rule" seems to say that you will only do the test "any pixel < 0.5" where the image pixel value is 1, which totally doesn't make any sense. If it's 1, then it will never be less than 0.5.
Finally I don't know what it means when you say you want your kernel to threshold the edge. Thresholding is done by a line of code like
thresholdedImage = edgeImage < thresholdValue;
not by morphology (if that's what you meant by "morh"). And of course you have to have the edge image beforehand.
So I'd love to help but you're going to have to explain better what you want.
  1 Comment
Wannabegeek on 17 Jul 2012
Thanks for your reply. I may not need this solution after all, but to be clear...
I am down sampling a 3D int16 image. The image also has a logical mask (floats) that needs to be down sampled and applied. When I down sample the mask, I get interpolation values that need to be binarized. I have found it might be better to mask the down sampled image with the interpolated mask (containing values on the open set (1-0) ). The alternative is to threshold and re-binarize the mask which has it's draw backs.
So now I have a down sampled image that has been masked. Since the mask contains interpolation effects, the edge is fuzzy. If I could pass a kernel around the edge of the data contained in the center of the frame, then I could make some first order statistical guess about what might be pixels I want to keep, around the fuzzy edge.
I imagine a square kernel that walks around the edge of the image planes, and I find the mean of the kernel. I then compute the std as well and throw out outliers and/or I apply a hard threshold to the values in the kernel.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by