Function for masking an image?
5 views (last 30 days)
Show older comments
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
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.
Answers (1)
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
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;
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!