MATLAB: Create narrow band of pixels under gray region image processingMATLAB I want to create a narrow band of pixels (white pixels) neighbouring the lower side of gray region. Please see the attached image. The expected output would be like: How can I do this? Please help. Thanks. Best Answer Threshold for black.mask = grayImage == 0;Extract the two largest regionsmask = bwareafilt(mask, 2);Then find the centroid or bounding boxprops = regionprops(mask, 'Centroid');and extract the lower black region. See if you can do this yourself.Call imerode() to shrink it. Then XOR the shrunken region with the original region to get just the edges.mask = imerode(lowerMask, true(9)); % Increase from 9 to get a wider white region.mask = xor(mask, lowerMask);Then set those pixels in the original image to white:grayImage(mask) = 255; Related SolutionsMATLAB: How to complete one of these two rectangles? I want to use it as mask for RGB image. Use bwconvhull();% Get convex hull of mask.mask = bwconvhull(mask);% Mask the image using bsxfun() functionmaskedRgbImage = bsxfun(@times, rgbImage, cast(mask, class(rgbImage)));You can use ~mask in the cast() if you want the inverse of the mask. MATLAB: How to extract a region of white pixel bounded by black pixel from white background It looks like a binary image. If it is, call imclearborderbinaryImage = imclearborder(binaryImage);This will get rid of all white/1/true regions touching the edge of the image. Related QuestionHow to cut part of an imageHow to delete the area around a circle in an imageChanging the pixel value of a region defined by its contour points
Best Answer