Function for masking an image?

5 views (last 30 days)
Ray
Ray on 20 Oct 2014
Commented: Image Analyst on 4 Jul 2016
function [masked] = maskImage(orig, mask)
Basically, this function takes a 3-D matrix (orig), and a 2-D logical mask matrix (mask) with the same number of rows and columns as the image matrix. This function should return an image matrix with the same dimensions as the original, where the original image colors show within the shape of the mask matrix and all other pixels are a quarter of their original intensity.
I'm having trouble with this since I am new to image processing and any help would be appreciated. Thank you.
  2 Comments
Ravinder Kaur
Ravinder Kaur on 4 Jul 2016
Masking of segmented binary image with original image to get texture details...
I have used your code for masking, but i am not getting the same texture as in an original image...?? I am also getting some extra outliers in output image
Like you are getting same gray values in Circle_mask_demo.
Image Analyst
Image Analyst on 4 Jul 2016
Ravinder, post your code and image(s) in a new question.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 20 Oct 2014
See my demos, attached. They do just that. Let me know if you have any other questions. Be sure to check out my Image Segmentation Tutorial in my File Exchange. It's pretty much the essentials of what most image analysis boils down to: thresholding, labeling, calling regionprops. You may have to do a bunch of things to the image until you get to a point where something can be thresholded, and those operations are image-dependent.
  3 Comments
Ray
Ray on 20 Oct 2014
I looked at the demos and they seem very advanced as compared to what I am trying to do. I know the outline of what I want to do but am having a hard time with the syntax etc. Basically, I am comparing the logical matrix to the input matrix. If the logical matrix at [1,1] is 1, then the masked matrix at [1,1] stays the same. But, if it is 0 at [1,1] then the masked matrix is divided by 4 at [1,1]. If you could help me with the syntax that would be great.
Image Analyst
Image Analyst on 20 Oct 2014
I thought my demos were all exceptionally well commented. Anyway, the line of code above will work for either gray level or RGB image. Can't get much simpler than one line of code. An alternative way for a gray scale image and that dividing by 4 things is:
grayImage(~mask) = grayImage(~mask)/4;

Sign in to comment.

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!