Click the above“Beginner’s Guide to Vision” to select and add a star or “pin”
Essential content delivered promptly
Display index image and grayscale image >> [X,map]=imread(‘trees.tif’);>> gmap=rgb2gray(map);>> figure,imshow(X,map);>> figure,imshow(X,gmap);Translate image using dilation functionI = imread(‘football.jpg’);se = translate(strel(1), [30 30]);% Move a planar structuring element down and to the right by 30 positionsJ = imdilate(I,se);% Translate image using dilation functionsubplot(121);imshow(I), title(‘Original Image’)subplot(122), imshow(J), title(‘Translated Image’);Horizontal and vertical flipI = imread(‘cameraman.tif’);Flip1=fliplr(I); % Flip matrix I horizontallysubplot(131);imshow(I);title(‘Original Image’);subplot(132);imshow(Flip1);title(‘Horizontal Mirror’);Flip2=flipud(I); % Flip matrix I verticallysubplot(133);imshow(Flip2);title(‘Vertical Mirror’);Image rotationI=imread(‘cameraman.tif’);B=imrotate(I,60,’bilinear’,’crop’);% Rotate image using bilinear interpolation and crop to match original sizesubplot(121),imshow(I),title(‘Original Image’);subplot(122),imshow(B),title(‘Rotated Image 60^{o}, Cropped’);Crop imageI = imread(‘circuit.tif’);I2 = imcrop(I,[75 68 130 112]);imshow(I), figure, imshow(I2)Draw contour>> I=imread(‘circuit.tif’);>> imshow(I)>> figure>> imcontour(I,3)Noise and filteringI=imread(‘cameraman.tif’);J=imnoise(I,’salt & pepper’,0.02);% Add salt and pepper noisesubplot(121),imshow(J);title(‘Noisy Image’)K=medfilt2(J);% Use a 3*3 neighborhood window for median filteringsubplot(122),imshow(K);title(‘Image after Median Filtering’)Summary of MATLAB digital image processing functions:1. Transformation of digital images① fft2: The fft2 function is used for the two-dimensional Fourier transform of digital images, e.g.: i=imread(‘104_8.tif’);j=fft2(i);② ifft2: The ifft2 function is used for the two-dimensional inverse Fourier transform of digital images, e.g: i=imread(‘104_8.tif’); j=fft2(i);k=ifft2(j);2. Functions for generating simulated noise and predefined filters① imnoise: Used to generate simulated noise for digital images, e.g: i=imread(‘104_8.tif’); j=imnoise(i,’gaussian’,0,0.02);% Simulate Gaussian noise
② fspecial: Used to generate predefined filters, e.g:h=fspecial(‘sobel’);% Sobel edge enhancement filterh=fspecial(‘gaussian’);% Gaussian low-pass filterh=fspecial(‘laplacian’);% Laplacian filterh=fspecial(‘log’);% Gaussian Laplacian (LoG) filterh=fspecial(‘average’);% Average filter2. Enhancement of digital images① Histogram: The imhist function is used to display the histogram of digital images, e.g:i=imread(‘104_8.tif’);imhist(i);② Histogram equalization: The histeq function is used for histogram equalization of digital images, e.g:i=imread(‘104_8.tif’);j=histeq(i);imshow(J)③ Contrast adjustment: The imadjust function is used for contrast adjustment of digital images, e.g: i=imread(‘104_8.tif’);j=imadjust(i,[0.3,0.7],[]);④ Log transformation: The log function is used for logarithmic transformation of digital images, e.g:i=imread(‘104_8.tif’);j=double(i);k=log(j);⑤ Convolution-based digital image filtering function: The filter2 function is used for digital image filtering, e.g: i=imread(‘104_8.tif’);h=[1,2,1;0,0,0;-1,-2,-1];j=filter2(h,i);
⑥ Linear filtering: Using two-dimensional convolution conv2 for filtering, e.g:i=imread(‘104_8.tif’);h=[1,1,1;1,1,1;1,1,1];h=h/9;j=conv2(i,h);⑦ Median filtering: The medfilt2 function is used for median filtering of digital images, e.g:i=imread(‘104_8.tif’);j=medfilt2(i);⑧ Sharpening(1) Using the Sobel operator to sharpen digital images, e.g:i=imread(‘104_8.tif’);h=[1,2,1;0,0,0;-1,-2,-1];% Sobel operatorj=filter2(h,i);(2) Using the Laplacian operator to sharpen digital images, e.g:i=imread(‘104_8.tif’);j=double(i);h=[0,1,0;1,-4,0;0,1,0];% Laplacian operatork=conv2(j,h,’same’);m=j-k;3. Edge detection of digital images① Sobel operator, e.g:i=imread(‘104_8.tif’);j =edge(i,’sobel’,thresh)② Prewitt operator, e.g:i=imread(‘104_8.tif’);j =edge(i,’prewitt’,thresh)③ Roberts operator, e.g:i=imread(‘104_8.tif’);j =edge(i,’roberts’,thresh)
④ LoG operator, e.g:i=imread(‘104_8.tif’);j =edge(i,’log’,thresh)⑤ Canny operator, e.g:i=imread(‘104_8.tif’);j =edge(i,’canny’,thresh)⑥ Zero-Cross operator, e.g:i=imread(‘104_8.tif’);j =edge(i,’zerocross’,thresh)4. Morphological digital image processing① Dilation: An operation to “lengthen” or “thicken” in binary digital images, the function imdilate performs dilation, e.g:a=imread(‘104_7.tif’);% Input binary digital imageb=[0 1 0;1 1 1;01 0];c=imdilate(a,b);② Erosion: The function imerode performs erosion, e.g:a=imread(‘104_7.tif’);% Input binary digital imageb=strel(‘disk’,1);c=imerode(a,b);③ Opening: Erosion followed by dilation is called opening, implemented using imopen, e.g:a=imread(‘104_8.tif’);b=strel(‘square’,2);c=imopen(a,b);④ Closing: Dilation followed by erosion is called closing, implemented using imclose, e.g: a=imread(‘104_8.tif’);b=strel(‘square’,2);c=imclose(a,b);Enhancement of digital images1. MATLAB implementation of histogram equalization1.1 imhist functionFunction: Calculate and display the color histogram of digital imagesFormat: imhist(I,n) imhist(X,map)Explanation: imhist(I,n) where n is the specified number of gray levels, default value is 256; imhist(X,map) calculates and displays the histogram of indexed color digital image X, map is the color palette. The stem(x,counts) can also display the histogram.1.2 imcontour functionFunction: Display the contour of digital imagesFormat: imcontour(I,n), imcontour(I,v)Explanation: n is the number of gray levels, v is the user-specified vector of selected gray levels.1.3 imadjust functionFunction: Adjust contrast through histogram transformationFormat: J=imadjust(I,[low high],[bottomtop],gamma) newmap=imadjust(map,[low high],[bottomtop],gamma)Explanation: J=imadjust(I,[low high],[bottomtop],gamma) where gamma is the correction factor r, [low high] is the gray range to be transformed in the original digital image, [bottom top] specifies the transformed gray range; newmap=imadjust(map,[low high],[bottom top],gamma) adjusts the color palette of indexed color digital images map. If [low high] and [bottom top] are both 2×3 matrices, it adjusts the three components R, G, B respectively.1.4 histeq functionFunction: Histogram equalizationFormat: J=histeq(I,hgram) J=histeq(I,n) [J,T]=histeq(I,…) newmap=histeq(X,map,hgram) newmap=histeq(X,map) [new,T]=histeq(X,…)Explanation: J=histeq(I,hgram) implements what is called “histogram specification,” transforming the histogram of the original image I into the user-specified vector hgram. Each element in hgram is in [0,1]; J=histeq(I,n) specifies the number of gray levels after equalization n, default value is 64; [J,T]=histeq(I,…) returns the transformation T that transforms the histogram of the digital image I into the histogram of the digital image J; newmap=histeq(X,map) and [new,T]=histeq(X,…) are for histogram equalization of indexed color digital image palettes.2. Noise and its MATLAB implementation imnoise functionFormat: J=imnoise(I,type) J=imnoise(I,type,parameter)Explanation: J=imnoise(I,type) returns the noisy digital image J after typical noise is added to the digital image I, parameters type and parameter are used to determine the type of noise and corresponding parameters.3. MATLAB implementation of digital image filtering3.1 conv2 functionFunction: Calculate two-dimensional convolutionFormat: C=conv2(A,B) C=conv2(Hcol,Hrow,A) C=conv2(…,’shape’)Explanation: For C=conv2(A,B), conv2 computes the convolution of matrices A and B, if [Ma,Na]=size(A), [Mb,Nb]=size(B), then size(C)=[Ma+Mb-1,Na+Nb-1];C=conv2(Hcol,Hrow,A) convolves matrix A with Hcol vector in the column direction and Hrow vector in the row direction; C=conv2(…,’shape’) specifies that conv2 returns part of the two-dimensional convolution result, parameter shape can take values as follows: 》full is the default value, returning all results of the two-dimensional convolution; 》same returns the middle part of the two-dimensional convolution result that matches the size of A; valid returns the part of the convolution result that was computed without using the edge padding of 0, when size(A)>size(B), size(C)=[Ma-Mb+1,Na-Nb+1].3.2 conv functionFunction: Calculate multi-dimensional convolutionFormat: Same as conv2 function3.3 filter2 functionFunction: Calculate two-dimensional linear digital filtering, used in conjunction with the fspecial functionFormat: Y=filter2(B,X) Y=filter2(B,X,’shape’)Explanation: For Y=filter2(B,X), filter2 uses the two-dimensional FIR filter in matrix B to filter data X, the result Y is obtained through two-dimensional cross-correlation, its size is the same as X; for Y=filter2(B,X,’shape’), the size of Y returned by filter2 is determined by the parameter shape, which can take the following values: 》full returns all results of the two-dimensional correlation, size(Y)>size(X); 》same returns the middle part of the two-dimensional cross-correlation result, Y is the same size as X; 》valid returns the result part of two-dimensional cross-correlation that was computed without using the edge padding of 0, with size(Y)<size(X). 3.4 fspecial functionFunction: Generate predefined filtersFormat: H=fspecial(type) H=fspecial(‘gaussian’,n,sigma) Gaussian low-pass filter H=fspecial(‘sobel’) Sobel horizontal edge enhancement filter H=fspecial(‘prewitt’) Prewitt horizontal edge enhancement filter H=fspecial(‘laplacian’,alpha) Approximate two-dimensional Laplacian operator filter H=fspecial(‘log’,n,sigma) Gaussian Laplacian (LoG) operator filter H=fspecial(‘average’,n) Average filter H=fspecial(‘unsharp’,alpha) Unsharp contrast enhancement filterExplanation: For the form H=fspecial(type), the fspecial function generates a two-dimensional filter H specified by type, the returned H is often used in conjunction with other filters.4. MATLAB implementation of color enhancement4.1 imfilter functionFunction: True color enhancementFormat: B=imfilter(A,h)Explanation: The original digital image A is filtered and enhanced according to the specified filter h, the enhanced digital image B has the same size and type as A.Transformation of digital images1. MATLAB implementation of discrete Fourier transform MATLAB functions fft, fft2, and fftn can implement one-dimensional, two-dimensional, and N-dimensional DFT algorithms respectively; while functions ifft, ifft2, and ifftn are used to compute inverse DFT.The calling formats of these functions are as follows: A=fft(X,N,DIM) where X is the input digital image; N is the sampling interval point, if X is less than this value, MATLAB will zero-fill X, otherwise it will truncate it to length N; DIM specifies the dimension for discrete Fourier transform. A=fft2(X,MROWS,NCOLS) where MROWS and NCOLS specify the size of X after zero-filling. A=fftn(X,SIZE)where SIZE is a vector, each element specifies the corresponding dimension of X after zero-filling. The calling formats of the functions ifft, ifft2, and ifftn are consistent with the corresponding discrete Fourier transform functions.Example: Two-dimensional Fourier spectrum of digital images% Read the original digital imageI=imread(‘lena.bmp’);imshow(I)% Compute the discrete Fourier spectrumJ=fftshift(fft2(I));figure;imshow(log(abs(J)),[8,10])2. MATLAB implementation of discrete cosine transform2.1. dCT2 functionFunction: Two-dimensional DCT transformFormat: B=dct2(A) B=dct2(A,m,n) B=dct2(A,[m,n]) Explanation: B=dct2(A) computes the DCT transform B of A, A and B have the same size; B=dct2(A,m,n) and B=dct2(A,[m,n]) make B of size m×n by zero-padding or cropping A.2.2. dict2 functionFunction: DCT inverse transformFormat: B=idct2(A) B=idct2(A,m,n) B=idct2(A,[m,n]) Explanation: B=idct2(A) computes the inverse DCT transform B of A, A and B have the same size; B=idct2(A,m,n) and B=idct2(A,[m,n]) make B of size m×n by zero-padding or cropping A.2.3. dctmtx functionFunction: Compute DCT transform matrixFormat: D=dctmtx(n)Explanation: D=dctmtx(n) returns an n×n DCT transform matrix, the output matrix D is of double type.3. MATLAB implementation of digital wavelet transformation3.1 One-dimensional wavelet transformation MATLAB implementation(1) dwt functionFunction: One-dimensional discrete wavelet transformFormat: [cA,cD]=dwt(X,’wname’) [cA,cD]=dwt(X,Lo_D,Hi_D)Explanation: [cA,cD]=dwt(X,’wname’) decomposes signal X using the specified wavelet basis function ‘wname’, cA and cD are the approximate and detail components respectively; [cA,cD]=dwt(X,Lo_D,Hi_D) decomposes the signal using specified filter groups Lo_D and Hi_D.(2) idwt functionFunction: One-dimensional discrete wavelet inverse transformFormat: X=idwt(cA,cD,’wname’) X=idwt(cA,cD,Lo_R,Hi_R) X=idwt(cA,cD,’wname’,L) X=idwt(cA,cD,Lo_R,Hi_R,L)Explanation: X=idwt(cA,cD,’wname’) reconstructs the original signal X from the approximate component cA and detail component cD through wavelet inverse transform. ‘wname’ is the selected wavelet function X=idwt(cA,cD,Lo_R,Hi_R) reconstructs the original signal X using specified reconstruction filters Lo_R and Hi_R. X=idwt(cA,cD,’wname’,L) and X=idwt(cA,cD,Lo_R,Hi_R,L) specify returning L points near the center of signal X.3.2 Two-dimensional wavelet transformation MATLAB implementation Functions for two-dimensional wavelet transformation————————————————- Function Name Function Purpose————————————————— dwt2 Two-dimensional discrete wavelet transform wavedec2 Multi-level wavelet decomposition of two-dimensional signals idwt2 Two-dimensional discrete wavelet inverse transform waverec2 Multi-level wavelet reconstruction of two-dimensional signals wrcoef2 Reconstruct a certain level of decomposition signal from multi-level wavelet decomposition upcoef2 Reconstruct approximate or detail components from multi-level wavelet decomposition detcoef2 Extract detail components of two-dimensional wavelet decomposition of signals appcoef2 Extract approximate components of two-dimensional wavelet decomposition of signals upwlev2 Single-level reconstruction of two-dimensional wavelet decomposition dwtpet2 Two-dimensional periodic wavelet transform idwtper2 Two-dimensional periodic wavelet inverse transform————————————————————-(1) wcodemat functionFunction: Perform pseudo-color coding on data matrixFormat: Y=wcodemat(X,NB,OPT,ABSOL) Y=wcodemat(X,NB,OPT) Y=wcodemat(X,NB) Y=wcodemat(X)Explanation: Y=wcodemat(X,NB,OPT,ABSOL) returns the coded matrix Y of data matrix X; NB is the maximum value for pseudo-coding, i.e., the coding range is 0 to NB, default value NB=16; OPT specifies the coding method (default value is ‘mat’), i.e.: OPT=’row’ , coded by row OPT=’col’ , coded by column OPT=’mat’ , coded by the entire matrix ABSOL is the control parameter of the function (default value is ‘1’), i.e.: ABSOL=0 returns the coded matrix ABSOL=1 returns the absolute value of the data matrix ABS(X)(2) dwt2 functionFunction: Two-dimensional discrete wavelet transformFormat: [cA,cH,cV,cD]=dwt2(X,’wname’) [cA,cH,cV,cD]=dwt2(X,Lo_D,Hi_D)Explanation: [cA,cH,cV,cD]=dwt2(X,’wname’) decomposes the two-dimensional signal X using the specified wavelet basis function ‘wname’; cA, cH, cV, cD are the approximate component, horizontal detail component, vertical detail component, and diagonal detail component respectively; [cA,cH,cV,cD]=dwt2(X,Lo_D,Hi_D) decomposes the signal X using specified decomposition low-pass and high-pass filters Lo_D and Hi_D.(3) wavedec2 functionFunction: Multi-level wavelet decomposition of two-dimensional signalsFormat: [C,S]=wavedec2(X,N,’wname’) [C,S]=wavedec2(X,N,Lo_D,Hi_D)Explanation: [C,S]=wavedec2(X,N,’wname’) performs N-level decomposition of the two-dimensional signal X using wavelet basis function ‘wname’; [C,S]=wavedec2(X,N,Lo_D,Hi_D) performs decomposition of the signal X using specified decomposition low-pass and high-pass filters Lo_D and Hi_D.(4) idwt2 functionFunction: Two-dimensional discrete wavelet inverse transformFormat: X=idwt2(cA,cH,cV,cD,’wname’) X=idwt2(cA,cH,cV,cD,Lo_R,Hi_R) X=idwt2(cA,cH,cV,cD,’wname’,S) X=idwt2(cA,cH,cV,cD,Lo_R,Hi_R,S)Explanation: X=idwt2(cA,cH,cV,cD,’wname’) reconstructs the original signal X from the wavelet decomposition approximate signal cA and detail signals cH, cH, cV, cD;X=idwt2(cA,cH,cV,cD,Lo_R,Hi_R) reconstructs the original signal X using specified reconstruction low-pass and high-pass filters Lo_R and Hi_R;X=idwt2(cA,cH,cV,cD,’wname’,S) and X=idwt2(cA,cH,cV,cD,Lo_R,Hi_R,S) return S data points near the center.Digital image processing toolbox1. Digital images and digital image data By default, MATLAB stores data in digital images as double precision type (double), which requires a large amount of storage; MATLAB also supports another type, unsigned integer (uint8), where each data in the digital image matrix occupies 1 byte. Conversion from uint8 to double ——————————————— Digital image type MATLAB statement ——————————————— Indexed color B=double(A)+1 Indexed color or true color B=double(A)/255 Binary digital image B=double(A) ——————————————— Conversion from double to uint8 ——————————————— Digital image type MATLAB statement ——————————————— Indexed color B=uint8(round(A-1)) Indexed color or true color B=uint8(round(A*255)) Binary digital image B=logical(uint8(round(A))) ———————————————2. Supported digital image types in digital image processing toolbox2.1 True color digital images R, G, B three components represent the color of a pixel. To read the pixel value at (100,50) in a digital image, you can check the triplet data (100,50,1:3). True color digital images can be stored as double precision, with brightness values ranging from [0,1]; a more conventional storage method is to use unsigned integers, with brightness values ranging from [0,255] 2.2 Indexed color digital images Contains two structures, one is the color palette, and the other is the digital image data matrix. The color palette is a matrix with 3 columns and several rows, where each row represents a color, and the 3 columns represent the intensity of red, green, and blue as double precision numbers. Note: In MATLAB, the color intensity of the palette is [0,1], where 0 represents the darkest and 1 represents the brightest. RGB values of common colors ——————————————– Color R G B Color R G B ——————————————– Black 0 0 1 Magenta 1 0 1 White 1 1 1 Cyan 0 1 1 Red 1 0 0 Sky Blue 0.67 0 1 Green 0 1 0 Orange 1 0.5 0 Blue 0 0 1 Dark Red 0.5 0 0 Yellow 1 1 0 Gray 0.5 0.5 0.5 ——————————————– Functions to generate standard palettes ————————————————- Function Name Palette ————————————————- Hsv Color saturation, starting and ending with red Hot Black – Red – Yellow – White Cool Cyan and Magenta hues Pink Pink hues Gray Linear grayscale Bone Grayscale with blue tint Jet A variant of Hsv, starting and ending with blue Copper Linear copper hue Prim Prism, alternating red, orange, yellow, green, and sky blue Flag Alternating red, white, blue, and black————————————————– By default, calling the above functions generates a 64×3 palette, and the user can also specify the size of the palette. Indexed color digital image data can also be of double or uint8 types. When the digital image data is of double type, the value 1 represents the first row in the palette, value 2 represents the second row, and so on. If the digital image data is of uint8 type, 0 represents the first row in the palette, value 1 represents the second row, and so on.2.3 Grayscale digital images Storing grayscale digital images only requires one data matrix. The data type can be double, [0,1]; or uint8, [0,255]2.4 Binary digital images Binary digital images only require one data matrix, where each pixel has two grayscale values, and can be stored in uint8 or double types. Functions in the MATLAB toolbox that return binary digital images use uint8 type.2.5 Digital image sequences The MATLAB toolbox supports connecting multiple frames of digital images into a digital image sequence.3. MATLAB digital image type conversion Digital image type conversion functions ————————————————————————— Function Name Function Purpose ————————————————————————— dither Digital image dithering, converting grayscale images to binary images, or dithering true color digital images to indexed color digital images gray2ind Convert grayscale digital images to indexed digital images grayslice Convert grayscale digital images to indexed color digital images by setting thresholds im2bw Convert true color, indexed color, and grayscale images to binary images by setting brightness thresholds ind2gray Convert indexed color digital images to grayscale digital images ind2rgb Convert indexed color digital images to true color digital images mat2gray Convert a data matrix to a grayscale image rgb2gray Convert a true color digital image to a grayscale digital image rgb2ind Convert true color digital images to indexed color digital images ————————————————————————4. Reading, writing, and querying digital image files4.1 Reading graphic digital image files The imread() function can be used to read graphic digital image files, syntax: A=imread(filename,fmt) [X,map]=imread(filename,fmt) […]=imread(filename) […]=imread(filename,idx) (only for TIF format files) […]=imread(filename,ref) (only for HDF format files) Typically, most digital images read are 8bit, and when these digital images are loaded into memory, MATLAB stores them in class uint8. MATLAB also supports 16bit PNG and TIF digital images, and when reading these types of files, MATLAB stores them in uint16. Note: For indexed digital images, even if the digital image array itself is of class uint8 or uint16, the imread function still reads the color mapping table and stores it in a double precision floating point array.4.2 Writing graphic digital image files Use the imwrite function, syntax as follows: imwrite(A,filename,fmt) imwrite(X,map,filename,fmt) imwrite(…,filename) imwrite(…,parameter,value) When saving digital images using the imwrite function, MATLAB’s default method is to simplify it to uint8 data format.4.3 Querying information of graphic digital image files imfinfo() function5. Displaying digital images5.1 Displaying indexed digital images Method 1: image(X) colormap(map) Method 2: imshow(X,map)5.2 Displaying grayscale digital images In MATLAB 7.0, to display a grayscale digital image, you can call the function imshow or imagesc (i.e., imagescale, digital image scaling function) (1) imshow function displays grayscale digital images Use imshow(I) or use explicitly specified grayscale level: imshow(I,32) Since MATLAB automatically scales grayscale digital images to fit the range of the color palette, you can use a custom-sized color palette. The calling format is as follows: imshow(I,[low,high]) where low and high are the minimum and maximum values of the data array respectively. (2) imagesc function displays grayscale digital images The following code uses two input parameters for the imagesc function to display a grayscale digital image imagesc(1,[0,1]); colormap(gray); The second parameter in the imagesc function determines the grayscale range. The first value in the grayscale range (usually 0) corresponds to the first value (color) in the color mapping table, while the second value (usually 1) corresponds to the last value (color) in the color mapping table. Values in the middle of the grayscale range linearly correspond to the remaining values (colors) in the color mapping table. When calling the imagesc function with only one parameter, any grayscale range can be used to display the digital image. In this calling method, the minimum value in the data matrix corresponds to the first color value in the color mapping table, and the maximum value in the data matrix corresponds to the last color value in the color mapping table.5.3 Displaying RGB digital images (1) image(RGB) Regardless of whether the type of RGB digital image is double floating point, or uint8 or uint16 unsigned integer type, MATLAB can correctly display it through the image function. RGB8 = uint8(round(RGB64×255)); % Convert double floating point to uint8 unsigned integer RGB64 = double(RGB8)/255; % Convert uint8 unsigned integer to double floating point RGB16 = uint16(round(RGB64×65535)); % Convert double floating point to uint16 unsigned integer RGB64 = double(RGB16)/65535; % Convert uint16 unsigned integer to double floating point (2) imshow(RGB) The parameter is an m×n×3 array5.4 Displaying binary digital images (1) imshow(BW) In MATLAB 7.0, binary digital images are a logical class that only includes two values, 0 and 1. Pixel 0 is displayed as black, and pixel 1 is displayed as white. During display, you can also use the NOT(~) command to invert the binary image, making value 0 display as white and 1 display as black. For example: imshow(~BW) (2) Additionally, a binary digital image can also be displayed using a color palette. If the image is of uint8 data type, value 0 is displayed as the first color in the palette, and value 1 is displayed as the second color.5.5 Directly displaying digital images from disk You can directly display the digital image file using the following command: imshow filename where filename is the name of the digital image file to be displayed. If the digital image is multi-frame, then imshow will only display the first frame. However, it should be noted that when using this method, the digital image data is not saved in the MATLAB 7.0 workspace. If you want to load the digital image into the workspace, you need to use the getimage function to retrieve the digital image data from the current handle graphics digital image object, The command format is: rgb = getimage;bwlabel Function: Label connected parts in binary digital images. L = bwlabel(BW,n) [L,num] = bwlabel(BW,n)isbw Function: Determine whether it is a binary digital image. Syntax: flag = isbw(A) Related commands: isind, isgray, isrgb 74. isgray Function: Determine whether it is a grayscale digital image. Syntax: flag = isgray(A) Related commands: isbw, isind, isrgb11. bwselect Function: Select objects in binary digital images.Syntax: BW2 = bwselect(BW1,c,r,n) BW2 = bwselect(BW1,n) [BW2,idx] = bwselect(…) Example BW1 = imread(‘text.tif’); c = [16 90 144]; r = [85 197 247]; BW2 = bwselect(BW1,c,r,4); imshow(BW1) figure, imshow(BW2)47. im2bw Function: Convert digital images to binary digital images. Syntax: BW = im2bw(I,level) BW = im2bw(X,map,level) BW = im2bw(RGB,level) Example load trees BW = im2bw(X,map,0.4); imshow(X,map)
Statement:Some content is sourced from the internet, intended for readers’ learning and communication purposes.The copyright of the article belongs to the original author.If there are any issues, please contact for removal.
Download 1: OpenCV-Contrib Extension Module Chinese Version Tutorial
Reply "Extension Module Chinese Tutorial" in the "Beginner's Guide to Vision" public account background to download the first OpenCV extension module tutorial in Chinese, covering installation of extension modules, SFM algorithms, stereo vision, target tracking, biological vision, super-resolution processing, etc. over twenty chapters of content.
Download 2: Python Vision Practical Project 52 Lectures
Reply "Python Vision Practical Project" in the "Beginner's Guide to Vision" public account background to download 31 practical vision projects including image segmentation, mask detection, lane line detection, vehicle counting, eyeliner addition, license plate recognition, character recognition, emotion detection, text content extraction, facial recognition, etc. to help quickly learn computer vision.
Download 3: OpenCV Practical Project 20 Lectures
Reply "OpenCV Practical Project 20 Lectures" in the "Beginner's Guide to Vision" public account background to download 20 practical projects based on OpenCV to achieve advanced learning of OpenCV.
Group Chat
Welcome to join the reader group of the public account to communicate with peers. Currently, there are WeChat groups for SLAM, 3D vision, sensors, autonomous driving, computational photography, detection, segmentation, recognition, medical imaging, GAN, algorithm competitions, etc. (will gradually be subdivided in the future). Please scan the WeChat number below to join the group, note: "Nickname + School/Company + Research Direction", for example: "Zhang San + Shanghai Jiao Tong University + Vision SLAM". Please follow the format, otherwise, it will not be approved. After successful addition, you will be invited into the relevant WeChat group based on research direction. Please do not send advertisements in the group, otherwise, you will be removed from the group, thank you for your understanding~