How to plot an intensity profile within given pix depth?

Hi guys,
Would someone please help me to do the following thing: I have an image of a roughly elliptical object. I know the outline coordinates of it. I would like to:
  1. Plot as a heat-map only pixels of this object that are 10 pixels or so from the object outline inward.
  2. Average the intensities of these 10 pixels at every position and plot this as a heat-map.
  3. Plot #2 on a perimeter of a circle starting from the default position.
The idea is to make an intensity profile within the given depth from the object outline (#1 and #2) and to find the angular distribution of intensities; on X axis angle, on Y axis pix intensities.
Thanks in advance, jakub

 Accepted Answer

You can the the pixels 10 out from your boundary by getting a binary image from your coordinates first using poly2mask. Then use imdilate to grow that blob out by 10 pixels. Then use bwperim() to get the new boundary locations' pixel values (Untested)
binaryImage = poly2mask(x, y, rows, columns);
SE = strel('disk', R, N)
biggerBlob = imdilate(binaryImage, SE);
perimPixels = bwperim(biggerBlob)
meanGL = mean(grayImage(perimPixels));

5 Comments

Thank you Image Analyst. I used your advice but slightly modified it. So I have coordinates of outer boundary and coordinates of boundary moved 10 pix inward. I masked raw image with poly2mask using outer boundary that gave me output image1. Then I applied poly2mask on image1 using inner boundary and multiply image1 *. (~mask1) It kind of work but when I multiply raw image by every element of mask, I get error that you can not multiply uint16 with logical mask. When I use image by every element of (uint16(mask), it works but somehow??? the image is weirdly dimmer on on sides, which is not the case in raw image. Any idea what could be wrong, is there other way to apply mask to image. Thanks again jakub
Not sure what code you used, but you can either cast both images to the same type, uint16 or double, or you can mask things like this
yourImage(binaryMaskImage) = 0; % or 1 or 255 or whatever you want.
OK, I will try it first thing in the morning. Also wanted to ask you one more thing. How to read pix by pix along the boundary and then move inward by one pix and read again pix by pixel. And then how to interpolate all rows to the same length?
Thanks again, j
To move inward you use imerode(). To move outward use imdilate(). Then use bwperim to get a mask of the outer layer of pixels and logical indexing like I showed you to get the mean value along that outer layer of pixels.
I understand but in that case I will get one mean value for each pixel layer. What I was thinking is to "linearize"the outer layer of pixels then do the same moving inward. something like an intensity profile. For example, for moving 5 pix in depth I will end up with 5 rows of pixels of a length of the perimeter for given pix layer. The rows will be of different length due to the difference in perimeter between outer and inner layer of pixels. Is there a way to interpolate the shorter pix rows to the length of outer pix layer?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!