Image processing: Is there a way to edit pixels based on neighbouring adjacent pixels?

3 views (last 30 days)
Hi, I'm doing some image processing with CT Scans and i want to separate the 3 main components sand, empty, calcite precipitation
Now, i used multithresh to convert it to RGB with 3 colours to visualize it and count the different colour pixels to calculate Area percentage of the components.
This is not optimal yet, because there are a lot of small red islands of calcite being misidentified in the middle of the yellow sand grains. I tried to remedy that by gaussian smoothing of the original (result below)
This is still not optimal, and I'd rather use something like bwareaopen (if there is something like that with RGB) to remove small 1or 2-pixel disturbances surrounded by pixels of another colour, or edit pixels based on surrounding pixels, so let's say if there is 6 of the 8 surrounding pixels of a different colour, the pixel is converted into that colour.
Is it possible to do that or to solve this in a different way? Use another kind of smoothing maybe?

Accepted Answer

Image Analyst
Image Analyst on 17 May 2020
Edited: Image Analyst on 17 May 2020
Yes, you can first get a mask of the sane that has blobs with the small holes (of calcite or whatever) you want to get rid of. Let's say the holes you want to get rid of have an area of 9 pixels or smaller, and if it's a hole 10 or larger than that you want to keep it. Then you get your binary image of just one class first, say, sandMask, then
% Only retain holes 10 pixels or bigger.
onlyBigBlobs = ~bwareaopen(~sandMask, 10);
  1 Comment
Wasgeht Siedasan
Wasgeht Siedasan on 18 May 2020
Thanks for the answer, your replies in other threads were also helpful to me since I am new to matlab. So you have to use a binary mask and bwareaopen, you can't do adjacency/neighbouring pixels based rules? Or is it just more convenient?
I don't know yet about how to work with masks, but I will try to figure it out using your other guides to do it, like this one (I think?) might be relevant:
If I have further questions, I'd come back and ask if thats cool?
Thanks again for all the work you do!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!