How to get pixel value around objects in greyscale image?
Show older comments
Hi!
I'm new to Matlab and stuck with one of my projects.
I am performing image analysis from grey scale images where the pixel intensity represents a specific concentration of element. In the image, I have ovoid objects that have a grey value between 0-40. My goal is to get the average grey value of pixels surrounding the ovoid objects (let's say 4 pixels width around the ovoid objects in any directions).
Here is a picture of what my original image looks like:

I thought to convert the image into binary and use the regionprops command to find objects but then, I'm stuck to:
- apply the mask of objects to the grey scale image
- isolate pixels surrounding the objects (with a 4 pixel width from the object edges) and get their values
At then end, I'm not sure that I'm trying to apply the best approach to reach my initial goal.
Here is the code I have written:
[FileName,PathName] = uigetfile('.tif','Choose tiff file to import...');
image = imread(strcat(PathName,FileName));
figure;imshow (image); title('original Image');
bw = im2bw(image,0.195);
filtim = medfilt2(bw);
filtim = ~filtim;
filtim = 1-filtim;
filtim = (filtim == 0);
bw2 = imclearborder(filtim);
bw3 = bwareaopen(bw2, 15);
figure;imshow (bw3); title('Segmented image');
s = regionprops(bw3, image, {'Centroid'});
If any body could help, it would be greatly appreciated.
Cheers
Guillaume
Accepted Answer
More Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!