![]() That function, though, only works on 2-D images–not on RGB images. Conveniently, the function roifilt2 allows me to operate on only a masked portion of an image. Yes! I like that mask, and can do a lot with it. Mask = imdilate(mask,strel( 'disk',2)) %Slight tweak here So instead, I’m going to quickly encircle the zebra using imfreehand, and use the resulting mask to eliminate all peripheral blobs. (That would presumably leave only the zebra.) But in this case, that would also eliminate all the small isolated regions around the zebra’s legs, and I would like to keep those. The documentation for regionprops shows how one could easily use that information to eliminate all but the largest object in the resulting image. Normally, I would use imclearborder to remove the large white region at the top of the image, and then, using regionprops, determine the areas of each connected blob. Mask = imfill(mask, 'holes') %Morphologically fill holes I like this as a starting point, so I’m going to use this and start refining: mask = bwareaopen(mask,100) %Remove small blobs Now at a glance I can construct a segmentation mask of the zebra, selecting only the indices that have a significant component within the area of interest: mask = ismember(X,) Ĭlearly, there’s a tradeoff between including more indices to “solidify” the zebra mask, and increasing the amount of background “noise” included in the segmentation. For instance, here I quantize the zebra into 16 colors and display the binary mask that each index represents: nColors = 16 Each of those “quantum levels” can be used to create a unique mask of the image. The function rgb2ind quantizes an image into a user-specified number of colors. In this approach, rather than manually selecting colors on which to base the segmentation mask, I’m going to let MATLAB do the work. ![]() Instead of going down that path, though, I’d like to demonstrate another useful approach to color segmentation. ( A GUI with sliders might facilitate that interaction!) I could also create additional masks in a similar manner and combine them, using the logical OR operation, until I achieved the desired segmentation. I could easily provide different tolerances for ranges above and below each of R, G, and B. Recognize here that each of those constraints on the binary variable “mask” is simply an additional logical AND that I’m applying. Img(:,:,3) <= targetColor(3) + tolerance By specifying a “tolerance” of 0.05 (i.e., 5 percent of the color range) we can readily create a mask of “not-zebra” by selecting all pixels that have those approximate red, green, and blue values: targetColor = In this image, for instance, we might recognize that the grass has an RGB intensity of roughly. Impixelregion provides a convenient tool for exploring the RGB (or grayscale) values underneath a small rectangle as you drag that rectangle over your image, the intensity values are updated and displayed in a separate figure. %Note that the |im2double| conversion conveniently scales the intensities to If I wanted to create a mask of a single user-selected color, for instance, I could use impixelregion to explore colors in a region, or I could invoke impixel to click-select color samples. There are several approaches to segmenting using color information. In fact, I’m going to use color to segment the zebra in this image, and then use the manual masking approach (using the imfreehand– mediated approach I used in the previous post) to fine-tune the mask. While I stand by that statement, I will also say that sometimes color does provide good information with which to create a segmentation mask. I previously wrote that I can usually get a good segmentation mask working in on or more grayscale representations of a color image. ![]() ![]() You might guess that doing so will entail segmenting the zebra–certainly the most difficult part of this problem. ![]() In this fourth post, I’m going to create the zebra image above. I started easy, and increased the difficulty level as I progressed. In the three previous entries in this guest series ( part 1, part 2, part 3) I’ve worked my way through some approaches to creating special image effects with MATLAB. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |