l = dir('asl/*.jpg'); s = strcat('asl/',l(10).name) s = asl/ASL-A.jpg I = imread(s); Ir = I(:,:,1); BWr = im2bw(Ir,graythresh(Ir)); figure, imshow(BWr); help bwlabel BWLABEL Label connected components in binary image. L = BWLABEL(BW,N) returns a matrix L, of the same size as BW, containing labels for the connected components in BW. N can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects; if the argument is omitted, it defaults to 8. The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object, the pixels labeled 2 make up a second object, and so on. [L,NUM] = BWLABEL(BW,N) returns in NUM the number of connected objects found in BW. Note: Comparing BWLABEL and BWLABELN ------------------------------------ BWLABEL supports 2-D inputs only, whereas BWLABELN support any input dimension. In some cases you might prefer to use BWLABELN even for 2-D problems because it can be faster. If you have a 2-D input whose objects are relatively "thick" in the vertical direction, BWLABEL will probably be faster; otherwise BWLABELN will probably be faster. Class Support ------------- BW can be logical or numeric, and it must be real, 2-D, and nonsparse. L is double. Example ------- BW = logical([1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 0 0]); L = bwlabel(BW,4); [r,c] = find(L == 2); See also bweuler, bwlabeln, bwselect. Reference page in Help browser doc bwlabel L = bwlabel(BWr,4); whos Name Size Bytes Class BWr 240x320 76800 logical array I 240x320x3 230400 uint8 array Ir 240x320 76800 uint8 array L 240x320 614400 double array l 28x1 8852 struct array s 1x13 26 char array Grand total is 461793 elements using 1007278 bytes max(max(L)) ans = 8 for i=1:8, ind = find(L == i); length(i) end ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 for i=1:8, ind = find(L == i); length(ind) end ans = 1 ans = 17136 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 for i=1:8, ind = find(L == i); if (length(ind) < 10) L(ind) = 0; emd end end ??? Undefined function or variable 'emd'. for i=1:8, ind = find(L == i); if (length(ind) < 10) L(ind) = 0; end end max(max(L)) ans = 2 ind0 = find(L == 0); whos Name Size Bytes Class BWr 240x320 76800 logical array I 240x320x3 230400 uint8 array Ir 240x320 76800 uint8 array L 240x320 614400 double array ans 1x1 8 double array i 1x1 8 double array ind 1x1 8 double array ind0 59664x1 477312 double array l 28x1 8852 struct array s 1x13 26 char array Grand total is 521460 elements using 1484614 bytes ind = find(L == 2); whos Name Size Bytes Class BWr 240x320 76800 logical array I 240x320x3 230400 uint8 array Ir 240x320 76800 uint8 array L 240x320 614400 double array ans 1x1 8 double array i 1x1 8 double array ind 17136x1 137088 double array ind0 59664x1 477312 double array l 28x1 8852 struct array s 1x13 26 char array Grand total is 538595 elements using 1621694 bytes BWr(ind0) = 0; figure, imshow(BWr); help bwlabel BWLABEL Label connected components in binary image. L = BWLABEL(BW,N) returns a matrix L, of the same size as BW, containing labels for the connected components in BW. N can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects; if the argument is omitted, it defaults to 8. The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object, the pixels labeled 2 make up a second object, and so on. [L,NUM] = BWLABEL(BW,N) returns in NUM the number of connected objects found in BW. Note: Comparing BWLABEL and BWLABELN ------------------------------------ BWLABEL supports 2-D inputs only, whereas BWLABELN support any input dimension. In some cases you might prefer to use BWLABELN even for 2-D problems because it can be faster. If you have a 2-D input whose objects are relatively "thick" in the vertical direction, BWLABEL will probably be faster; otherwise BWLABELN will probably be faster. Class Support ------------- BW can be logical or numeric, and it must be real, 2-D, and nonsparse. L is double. Example ------- BW = logical([1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 0 0]); L = bwlabel(BW,4); [r,c] = find(L == 2); See also bweuler, bwlabeln, bwselect. Reference page in Help browser doc bwlabel help bwlabeln BWLABELN Label connected components in N-D binary image. L = BWLABELN(BW) returns a label matrix, L, containing labels for the connected components in BW. BW can have any dimension; L is the same size as BW. The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object, the pixels labeled 2 make up a second object, and so on. The default connectivity is 8 for two dimensions, 26 for three dimensions, and CONNDEF(NDIMS(BW),'maximal') for higher dimensions. [L,NUM] = BWLABELN(BW) returns the number of connected objects found in BW. [L,NUM] = BWLABELN(BW,CONN) specifies the desired connectivity. CONN may have the following scalar values: 4 two-dimensional four-connected neighborhood 8 two-dimensional eight-connected neighborhood 6 three-dimensional six-connected neighborhood 18 three-dimensional 18-connected neighborhood 26 three-dimensional 26-connected neighborhood Connectivity may be defined in a more general way for any dimension by using for CONN a 3-by-3-by- ... -by-3 matrix of 0s and 1s. The 1-valued elements define neighborhood locations relative to the center element of CONN. CONN must be symmetric about its center element. Note: Comparing BWLABEL and BWLABELN ------------------------------------ BWLABEL supports 2-D inputs only, whereas BWLABELN support any input dimension. In some cases you might prefer to use BWLABELN even for 2-D problems because it can be faster. If you have a 2-D input whose objects are relatively "thick" in the vertical direction, BWLABEL will probably be faster; otherwise BWLABELN will probably be faster. Class Support ------------- BW can be numeric or logical, and it must be real and nonsparse. L is double. Example ------- BW = cat(3,[1 1 0; 0 0 0; 1 0 0],... [0 1 0; 0 0 0; 0 1 0],... [0 1 1; 0 0 0; 0 0 1]) bwlabeln(BW) See also bwlabel. Reference page in Help browser doc bwlabeln help bwlabel BWLABEL Label connected components in binary image. L = BWLABEL(BW,N) returns a matrix L, of the same size as BW, containing labels for the connected components in BW. N can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects; if the argument is omitted, it defaults to 8. The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object, the pixels labeled 2 make up a second object, and so on. [L,NUM] = BWLABEL(BW,N) returns in NUM the number of connected objects found in BW. Note: Comparing BWLABEL and BWLABELN ------------------------------------ BWLABEL supports 2-D inputs only, whereas BWLABELN support any input dimension. In some cases you might prefer to use BWLABELN even for 2-D problems because it can be faster. If you have a 2-D input whose objects are relatively "thick" in the vertical direction, BWLABEL will probably be faster; otherwise BWLABELN will probably be faster. Class Support ------------- BW can be logical or numeric, and it must be real, 2-D, and nonsparse. L is double. Example ------- BW = logical([1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 0 0]); L = bwlabel(BW,4); [r,c] = find(L == 2); See also bweuler, bwlabeln, bwselect. Reference page in Help browser doc bwlabel help bwselect BWSELECT Select objects in binary image. BW2 = BWSELECT(BW1,C,R,N) returns a binary image containing the objects that overlap the pixel (R,C). R and C can be scalars or equal-length vectors. If R and C are vectors, BW2 contains the set of objects overlapping with any of the pixels (R(k),C(k)). N can have a value of either 4 or 8 (the default), where 4 specifies 4-connected objects and 8 specifies 8-connected objects. Objects are connected sets of "on" pixels (i.e., having value of 1). BW2 = BWSELECT(BW1,N) displays the image BW1 on the screen and lets you select the (R,C) coordinates using the mouse. If you omit BW1, BWSELECT operates on the image in the current axes. Use normal button clicks to add points. Pressing or removes the previously selected point. A shift-click, right-click, or double-click selects the final point; pressing finishes the selection without adding a point. [BW2,IDX] = BWSELECT(...) returns the linear indices of the pixels belonging to the selected objects. BW2 = BWSELECT(X,Y,BW1,Xi,Yi,N) uses the vectors X and Y to establish a nondefault spatial coordinate system for BW1. Xi and Yi are scalars or equal-length vectors that specify locations in this coordinate system. [X,Y,BW2,IDX,Xi,Yi] = BWSELECT(...) returns the XData and YData in X and Y; the output image in BW2; linear indices of the pixels belonging to the selected objects in IDX; and the specified spatial coordinates Xi and Yi. If bwselect is called with no output arguments, the resulting image is displayed in a new figure. Class Support ------------- The input image BW1 can be logical or any numeric type and must be 2-D and nonsparse. The output image BW2 is logical. Example ------- BW1 = imread('text.png'); c = [126 187 11]; r = [34 172 20]; BW2 = bwselect(BW1,c,r,4); imview(BW1) imview(BW2) See also imfill, bwlabel, roipoly, roifill. Reference page in Help browser doc bwselect help images Image Processing Toolbox Version 4.2 (R14) 05-May-2004 Image display. colorbar - Display colorbar (MATLAB Toolbox). getimage - Get image data from axes. image - Create and display image object (MATLAB Toolbox). imagesc - Scale data and display as image (MATLAB Toolbox). immovie - Make movie from multiframe image. imshow - Display image in Handle Graphics figure. imview - Display image in the image viewer. montage - Display multiple image frames as rectangular montage. movie - Play recorded movie frames (MATLAB Toolbox). subimage - Display multiple images in single figure. truesize - Adjust display size of image. warp - Display image as texture-mapped surface. Image file I/O. dicominfo - Read metadata from a DICOM message. dicomread - Read a DICOM image. dicomuid - Generate DICOM unique identifier. dicomwrite - Write a DICOM image. dicom-dict.txt - Text file containing DICOM data dictionary. imfinfo - Return information about image file (MATLAB Toolbox). imread - Read image file (MATLAB Toolbox). imwrite - Write image file (MATLAB Toolbox). Image arithmetic. imabsdiff - Compute absolute difference of two images. imadd - Add two images, or add constant to image. imcomplement - Complement image. imdivide - Divide two images, or divide image by constant. imlincomb - Compute linear combination of images. immultiply - Multiply two images, or multiply image by constant. imsubtract - Subtract two images, or subtract constant from image. ippl - Check for presence of IPPL. Geometric transformations. checkerboard - Create checkerboard image. findbounds - Find output bounds for geometric transformation. fliptform - Flip the input and output roles of a TFORM struct. imcrop - Crop image. imresize - Resize image. imrotate - Rotate image. imtransform - Apply geometric transformation to image. makeresampler - Create resampler structure. maketform - Create geometric transformation structure (TFORM). tformarray - Apply geometric transformation to N-D array. tformfwd - Apply forward geometric transformation. tforminv - Apply inverse geometric transformation. Image registration. cpstruct2pairs - Convert CPSTRUCT to valid pairs of control points. cp2tform - Infer geometric transformation from control point pairs. cpcorr - Tune control point locations using cross-correlation. cpselect - Control point selection tool. normxcorr2 - Normalized two-dimensional cross-correlation. Pixel values and statistics. corr2 - Compute 2-D correlation coefficient. imcontour - Create contour plot of image data. imhist - Display histogram of image data. impixel - Determine pixel color values. improfile - Compute pixel-value cross-sections along line segments. mean2 - Compute mean of matrix elements. pixval - Display information about image pixels. regionprops - Measure properties of image regions. std2 - Compute standard deviation of matrix elements. Image analysis. bwboundaries - Trace region boundaries in binary image. bwtraceboundary - Trace object in binary image. edge - Find edges in intensity image. qtdecomp - Perform quadtree decomposition. qtgetblk - Get block values in quadtree decomposition. qtsetblk - Set block values in quadtree decomposition. Image enhancement. adapthisteq - Perform adaptive histogram equalization using CLAHE. decorrstretch - Apply a decorrelation stretch to a multichannel image. histeq - Enhance contrast using histogram equalization. imadjust - Adjust image intensity values or colormap. imnoise - Add noise to an image. medfilt2 - Perform 2-D median filtering. ordfilt2 - Perform 2-D order-statistic filtering. stretchlim - Find limits to contrast stretch an image. uintlut - Computes new array values based on lookup table. wiener2 - Perform 2-D adaptive noise-removal filtering. Linear filtering. convmtx2 - Compute 2-D convolution matrix. fspecial - Create predefined filters. imfilter - Filter 2-D and N-D images. Linear 2-D filter design. freqspace - Determine 2-D frequency response spacing (MATLAB Toolbox). freqz2 - Compute 2-D frequency response. fsamp2 - Design 2-D FIR filter using frequency sampling. ftrans2 - Design 2-D FIR filter using frequency transformation. fwind1 - Design 2-D FIR filter using 1-D window method. fwind2 - Design 2-D FIR filter using 2-D window method. Image deblurring. deconvblind - Deblur image using blind deconvolution. deconvlucy - Deblur image using Lucy-Richardson method. deconvreg - Deblur image using regularized filter. deconvwnr - Deblur image using Wiener filter. edgetaper - Taper edges using point-spread function. otf2psf - Optical transfer function to point-spread function. psf2otf - Point-spread function to optical transfer function. Image transforms. dct2 - 2-D discrete cosine transform. dctmtx - Discrete cosine transform matrix. fan2para - Convert fan-beam projections to parallel-beam. fanbeam - Compute fan-beam transform. fft2 - 2-D fast Fourier transform (MATLAB Toolbox). fftn - N-D fast Fourier transform (MATLAB Toolbox). fftshift - Reverse quadrants of output of FFT (MATLAB Toolbox). idct2 - 2-D inverse discrete cosine transform. ifft2 - 2-D inverse fast Fourier transform (MATLAB Toolbox). ifftn - N-D inverse fast Fourier transform (MATLAB Toolbox). ifanbeam - Compute inverse fan-beam transform. iradon - Compute inverse Radon transform. para2fan - Convert parallel-beam projections to fan-beam. phantom - Generate a head phantom image. radon - Compute Radon transform. Neighborhood and block processing. bestblk - Choose block size for block processing. blkproc - Implement distinct block processing for image. col2im - Rearrange matrix columns into blocks. colfilt - Columnwise neighborhood operations. im2col - Rearrange image blocks into columns. nlfilter - Perform general sliding-neighborhood operations. Morphological operations (intensity and binary images). conndef - Default connectivity. imbothat - Perform bottom-hat filtering. imclearborder - Suppress light structures connected to image border. imclose - Close image. imdilate - Dilate image. imerode - Erode image. imextendedmax - Extended-maxima transform. imextendedmin - Extended-minima transform. imfill - Fill image regions and holes. imhmax - H-maxima transform. imhmin - H-minima transform. imimposemin - Impose minima. imopen - Open image. imreconstruct - Morphological reconstruction. imregionalmax - Regional maxima. imregionalmin - Regional minima. imtophat - Perform tophat filtering. watershed - Watershed transform. Morphological operations (binary images). applylut - Perform neighborhood operations using lookup tables. bwarea - Compute area of objects in binary image. bwareaopen - Binary area open (remove small objects). bwdist - Compute distance transform of binary image. bweuler - Compute Euler number of binary image. bwhitmiss - Binary hit-miss operation. bwlabel - Label connected components in 2-D binary image. bwlabeln - Label connected components in N-D binary image. bwmorph - Perform morphological operations on binary image. bwpack - Pack binary image. bwperim - Determine perimeter of objects in binary image. bwselect - Select objects in binary image. bwulterode - Ultimate erosion. bwunpack - Unpack binary image. makelut - Construct lookup table for use with applylut. Structuring element (STREL) creation and manipulation. getheight - Get strel height. getneighbors - Get offset location and height of strel neighbors getnhood - Get strel neighborhood. getsequence - Get sequence of decomposed strels. isflat - Return true for flat strels. reflect - Reflect strel about its center. strel - Create morphological structuring element. translate - Translate strel. Region-based processing. poly2mask - Convert region-of-interest polygon to mask. roicolor - Select region of interest, based on color. roifill - Smoothly interpolate within arbitrary region. roifilt2 - Filter a region of interest. roipoly - Select polygonal region of interest. Colormap manipulation. brighten - Brighten or darken colormap (MATLAB Toolbox). cmpermute - Rearrange colors in colormap. cmunique - Find unique colormap colors and corresponding image. colormap - Set or get color lookup table (MATLAB Toolbox). imapprox - Approximate indexed image by one with fewer colors. rgbplot - Plot RGB colormap components (MATLAB Toolbox). Color space conversions. applycform - Apply device-independent color space transformation. hsv2rgb - Convert HSV values to RGB color space (MATLAB Toolbox). iccread - Read ICC color profile. lab2double - Convert Lab color values to double. lab2uint16 - Convert Lab color values to uint16. lab2uint8 - Convert Lab color values to uint8. makecform - Create device-independent color space transform structure. ntsc2rgb - Convert NTSC values to RGB color space. rgb2hsv - Convert RGB values to HSV color space (MATLAB Toolbox). rgb2ntsc - Convert RGB values to NTSC color space. rgb2ycbcr - Convert RGB values to YCBCR color space. whitepoint - Returns XYZ values of standard illuminants. xyz2double - Convert XYZ color values to double. xyz2uint16 - Convert XYZ color values to uint16. ycbcr2rgb - Convert YCBCR values to RGB color space. Interactive mouse utility functions. getline - Select polyline with mouse. getpts - Select points with mouse. getrect - Select rectangle with mouse. ICC color profiles. lab8.icm - 8-bit Lab profile. monitor.icm - Typical monitor profile. Sequel Imaging, Inc., used with permission. sRGB.icm - sRGB profile. Hewlett-Packard, used with permission. swopcmyk.icm - CMYK input profile. Eastman Kodak, used with permission. Array operations. circshift - Shift array circularly (MATLAB Toolbox). padarray - Pad array. Image types and type conversions. dither - Convert image using dithering. gray2ind - Convert intensity image to indexed image. grayslice - Create indexed image from intensity image by thresholding. graythresh - Compute global image threshold using Otsu's method. im2bw - Convert image to binary image by thresholding. im2double - Convert image array to double precision. im2java - Convert image to Java image (MATLAB Toolbox). im2java2d - Convert image to Java BufferedImage. im2uint8 - Convert image array to 8-bit unsigned integers. im2uint16 - Convert image array to 16-bit unsigned integers. ind2gray - Convert indexed image to intensity image. ind2rgb - Convert indexed image to RGB image (MATLAB Toolbox). label2rgb - Convert label matrix to RGB image. mat2gray - Convert matrix to intensity image. rgb2gray - Convert RGB image or colormap to grayscale. rgb2ind - Convert RGB image to indexed image. Toolbox preferences. iptgetpref - Get value of Image Processing Toolbox preference. iptsetpref - Set value of Image Processing Toolbox preference. Demos. iptdemos - Index of Image Processing Toolbox demos. whos Name Size Bytes Class BWr 240x320 76800 logical array I 240x320x3 230400 uint8 array Ir 240x320 76800 uint8 array L 240x320 614400 double array ans 1x1 8 double array i 1x1 8 double array ind 17136x1 137088 double array ind0 59664x1 477312 double array l 28x1 8852 struct array s 1x13 26 char array Grand total is 538595 elements using 1621694 bytes Ir1 = uint8(BWr); max(max(Ir1)) ans = 1 ind = find(Ir1 == 1); Ir1(ind) = 255; max(mmax(Ir1)) ??? Undefined command/function 'mmax'. max(max(Ir1)) ans = 255 Ig1 = uint8(zeros(size(Ir1))); whos Name Size Bytes Class BWr 240x320 76800 logical array I 240x320x3 230400 uint8 array Ig1 240x320 76800 uint8 array Ir 240x320 76800 uint8 array Ir1 240x320 76800 uint8 array L 240x320 614400 double array ans 1x1 1 uint8 array i 1x1 8 double array ind 17136x1 137088 double array ind0 59664x1 477312 double array l 28x1 8852 struct array s 1x13 26 char array Grand total is 692195 elements using 1775287 bytes Ib1 = uint8(zeros(size(Ir1))); Ic = [Ir1; Ig1; Ib1]; whos Name Size Bytes Class BWr 240x320 76800 logical array I 240x320x3 230400 uint8 array Ib1 240x320 76800 uint8 array Ic 720x320 230400 uint8 array Ig1 240x320 76800 uint8 array Ir 240x320 76800 uint8 array Ir1 240x320 76800 uint8 array L 240x320 614400 double array ans 1x1 1 uint8 array i 1x1 8 double array ind 17136x1 137088 double array ind0 59664x1 477312 double array l 28x1 8852 struct array s 1x13 26 char array Grand total is 999395 elements using 2082487 bytes Ic = [Ir1 Ig1 Ib1]; whos Name Size Bytes Class BWr 240x320 76800 logical array I 240x320x3 230400 uint8 array Ib1 240x320 76800 uint8 array Ic 240x960 230400 uint8 array Ig1 240x320 76800 uint8 array Ir 240x320 76800 uint8 array Ir1 240x320 76800 uint8 array L 240x320 614400 double array ans 1x1 1 uint8 array i 1x1 8 double array ind 17136x1 137088 double array ind0 59664x1 477312 double array l 28x1 8852 struct array s 1x13 26 char array Grand total is 999395 elements using 2082487 bytes Ic(:,:,1) = Ir1; ??? Subscripted assignment dimension mismatch. clear Ic Ic(:,:,1) = Ir1; Ic(:,:,2) = Ig1; Ic(:,:,3) = Ib1; imshow(Ic); Ic(:,:,2) = Ir1; imshow(Ic); Ic(:,:,2) = Ib1; Ic(:,:,3) = Ir1; imshow(Ic); Ic(:,:,1) = Ib1; Ic(:,:,2) = Ir1; imshow(Ic); diary;