Separate the rock in the image below from the background

6 views (last 30 days)
I want to separate this rock in the following image from the background. Although I am new in this field, would you tell me, step by step, how to do it? Thanks in advance.

Answers (2)

KALYAN ACHARJYA
KALYAN ACHARJYA on 25 May 2019
Edited: KALYAN ACHARJYA on 25 May 2019
You can do that by image segmentation. Here the background of Image is distinctly different from foreground object (therefore it may easy).
Adjust the threshold vale, but for complex images (that menas where foregorunf objects are mixed with background) such cases you have to look for little advance segmentation algorithms.
See Otsu method, Adaptive threshold, Edge detection and many more basic segmentation algorithms, if this not works perfectly. Those Matlab function I have used are basics, read in Matlab documentation.
Suggested Book: Read Image Segmenation Chapter in Digital Image Processing using Matlab by Gonzalez
im=imread('image.jpeg');
grayImage=rgb2gray(im);
%% Basic Thresholding
thresholdValue=180;
result=imcomplement(grayImage<=thresholdValue);
mask=imcomplement(bwareafilt(result,1,'Largest'));
RGB_result=bsxfun(@times,im,cast(mask,'like',im));
imshow(RGB_result);
uu.png
  6 Comments
Vaishnavi Gulave
Vaishnavi Gulave on 28 Apr 2023
  • Assessment result: incorrectIs the binary mask a valid mask for this image?The submission must contain a variable named curlingMask.Check the red feedback message for specific hints.
  • Assessment result: incorrectDoes the mask successfully separate the curling stones from the background?
  • If your segmentation has more or less regions than curling stones, you may want to try using either morphology or the Image Region Analyzer App to help you. You may have very small regions that are hard to see. Run you code in MATLAB and zoom in.
  • If your mask needs refinement, a good way to identify where the mask is not working well is to create a masked image and look at the mask along the borders of a curling stone. If you're struggling, try converting the image to grayscale and testing different approaches in the Image Segmenter App. Then examine the generated code.
showing these errors
Image Analyst
Image Analyst on 28 Apr 2023
@Vaishnavi Gulave Where did that come from? I don't see any curling stones in the original poster's submission up at the top. No idea what you're talking about. You should probably start your own discussion thread and post your m-file and your image file.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Sign in to comment.


Image Analyst
Image Analyst on 25 May 2019
I would try the Color Thresholder on the Apps tab of the MATLAB tool ribbon. Experiment with different color spaces, though I think HSV might be your best bet. You can have it export code once you've found the thresholds.
You then might do some clean up by using bwareafilt() to extract the largest blob, or blobs within some size range that you this is valid (in case you also want the small stone posts).

Community Treasure Hunt

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

Start Hunting!