• 【图像分割】图像检测(分割、特征提取)、各种特征(面积等)的测量和过滤(Matlab代码实现)


     💥💥💞💞欢迎来到本博客❤️❤️💥💥

    🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

    ⛳️座右铭:行百里者,半于九十。

    📋📋📋本文目录如下:🎁🎁🎁

    目录

    💥1 概述

    📚2 运行结果

    🎉3 参考文献

    🌈4 Matlab代码实现


    💥1 概述

    【图像分割】图像检测(分割、特征提取)、各种特征(面积等)的测量和过滤

    本文提供了一个适合初学者的教程,旨在演示图像检测(分割、特征提取)以及各种特征(如面积)的测量和过滤(只提取某些对象)。

    首先,该教程介绍了如何找到图像中的所有对象(硬币),然后根据指定的直径过滤结果,筛选出特定直径的对象。通过一个简单的示例,展示了阈值处理、标记和区域属性的基本概念。

    对于那些刚开始接触 MATLAB 图像处理功能的同学来说,这个教程是一个很好的起点。在他们深入学习更复杂的算法之前,可以通过这个教程加深对基本概念和技术的理解。

    为了完成这个教程,需要安装图像处理工具箱,因为它演示了该工具箱提供的某些功能。同时,教程使用了工具箱自带的一个名为“硬币”的示例图像作为演示对象。

    该教程的优点在于,它提供了一种直观和实用的方法,帮助初学者理解如何使用 MATLAB 对图像进行处理和分析。通过学习如何进行图像分割、特征提取和过滤,读者将受益于这些基本概念,并能够应用它们解决更为复杂的图像处理问题。这个教程对于那些有兴趣进一步探索图像处理领域的学生、研究人员和工程师来说,都是一个很好的起点。

    📚2 运行结果

    部分代码:

    1. % Read in a standard MATLAB demo image of coins (US nickles and dimes, which are 5 cent and 10 cent coins). This image ships with MATLAB.
    2. baseFileName = 'coins.png';
    3. folder = fileparts(which(baseFileName)); % Determine where demo folder is (works with all versions).
    4. fullFileName = fullfile(folder, baseFileName);
    5. fprintf('Full File Name = "%s".\n', fullFileName);
    6. if ~exist(fullFileName, 'file')
    7. % It doesn't exist in the current folder.
    8. % Look on the search path.
    9. if ~exist(baseFileName, 'file')
    10. % It doesn't exist on the search path either.
    11. % Alert user that we can't find the image.
    12. warningMessage = sprintf('Error: the input image file\n%s\nwas not found.\nClick OK to exit the demo.', fullFileName);
    13. uiwait(warndlg(warningMessage));
    14. fprintf(1, 'Finished running BlobsDemo.m.\n');
    15. return;
    16. end
    17. % Found it on the search path. Construct the file name.
    18. fullFileName = baseFileName; % Note: don't prepend the folder.
    19. end
    20. % If we get here, we should have found the image file.
    21. originalImage = imread(fullFileName);
    22. % Check to make sure that it is grayscale, just in case the user substituted their own image.
    23. [rows, columns, numberOfColorChannels] = size(originalImage);
    24. if numberOfColorChannels > 1
    25. promptMessage = sprintf('Your image file has %d color channels.\nThis demo was designed for grayscale images.\nDo you want me to convert it to grayscale for you so you can continue?', numberOfColorChannels);
    26. button = questdlg(promptMessage, 'Continue', 'Convert and Continue', 'Cancel', 'Convert and Continue');
    27. if strcmp(button, 'Cancel')
    28. fprintf(1, 'Finished running BlobsDemo.m.\n');
    29. return;
    30. end
    31. % Do the conversion using standard book formula
    32. originalImage = rgb2gray(originalImage);
    33. end
    34. % Display the grayscale image.
    35. subplot(3, 3, 1);
    36. imshow(originalImage);
    37. % Maximize the figure window.
    38. hFig1 = gcf;
    39. hFig1.Units = 'normalized';
    40. hFig1.WindowState = 'maximized'; % Go to full screen.
    41. hFig1.NumberTitle = 'off'; % Get rid of "Figure 1"
    42. hFig1.Name = 'Demo by Image Analyst'; % Put this into title bar.
    43. % Force it to display RIGHT NOW (otherwise it might not display until it's all done, unless you've stopped at a breakpoint.)
    44. drawnow;
    45. caption = sprintf('Original "coins" image showing\n6 nickels (the larger coins) and 4 dimes (the smaller coins).');
    46. title(caption, 'FontSize', captionFontSize);
    47. axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
    48. % Just for fun, let's get its histogram and display it.
    49. [pixelCount, grayLevels] = imhist(originalImage);
    50. subplot(3, 3, 2);
    51. bar(pixelCount);
    52. title('Histogram of original image', 'FontSize', captionFontSize);
    53. xlim([0 grayLevels(end)]); % Scale x axis manually.
    54. grid on;
    55. %------------------------------------------------------------------------------------------------------------------------------------------------------
    56. % Threshold the image to get a binary image (only 0's and 1's) of class "logical."
    57. % Method #1: using im2bw()
    58. % normalizedThresholdValue = 0.4; % In range 0 to 1.
    59. % thresholdValue = normalizedThresholdValue * max(max(originalImage)); % Gray Levels.
    60. % binaryImage = im2bw(originalImage, normalizedThresholdValue); % One way to threshold to binary
    61. % Method #2: using a logical operation.
    62. thresholdValue = 100;
    63. binaryImage = originalImage > thresholdValue; % Bright objects will be chosen if you use >.
    64. % ========== IMPORTANT OPTION ============================================================
    65. % Use < if you want to find dark objects instead of bright objects.
    66. % binaryImage = originalImage < thresholdValue; % Dark objects will be chosen if you use <.
    67. % Do a "hole fill" to get rid of any background pixels or "holes" inside the blobs.
    68. binaryImage = imfill(binaryImage, 'holes');
    69. % Show the threshold as a vertical red bar on the histogram.
    70. hold on;
    71. maxYValue = ylim;
    72. line([thresholdValue, thresholdValue], maxYValue, 'Color', 'r');
    73. % Place a text label on the bar chart showing the threshold.
    74. annotationText = sprintf('Thresholded at %d gray levels', thresholdValue);
    75. % For text(), the x and y need to be of the data class "double" so let's cast both to double.
    76. text(double(thresholdValue + 5), double(0.5 * maxYValue(2)), annotationText, 'FontSize', 10, 'Color', [0 .5 0]);
    77. text(double(thresholdValue - 70), double(0.94 * maxYValue(2)), 'Background', 'FontSize', 10, 'Color', [0 0 .5]);
    78. text(double(thresholdValue + 50), double(0.94 * maxYValue(2)), 'Foreground', 'FontSize', 10, 'Color', [0 0 .5]);
    79. % Display the binary image.
    80. subplot(3, 3, 3);
    81. imshow(binaryImage);
    82. title('Binary Image, obtained by thresholding', 'FontSize', captionFontSize);
    83. %------------------------------------------------------------------------------------------------------------------------------------------------------
    84. % Identify individual blobs by seeing which pixels are connected to each other. This is called "Connected Components Labeling".
    85. % Each group of connected pixels will be given a label, a number, to identify it and distinguish it from the other blobs.
    86. % Do connected components labeling with either bwlabel() or bwconncomp().
    87. [labeledImage, numberOfBlobs] = bwlabel(binaryImage, 8); % Label each blob so we can make measurements of it
    88. % labeledImage is an integer-valued image where all pixels in the blobs have values of 1, or 2, or 3, or ... etc.
    89. subplot(3, 3, 4);
    90. imshow(labeledImage, []); % Show the gray scale image.
    91. title('Labeled Image, from bwlabel()', 'FontSize', captionFontSize);
    92. drawnow;
    93. % Let's assign each blob a different color to visually show the user the distinct blobs.
    94. coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
    95. % coloredLabels is an RGB image. We could have applied a colormap instead (but only with R2014b and later)
    96. subplot(3, 3, 5);
    97. imshow(coloredLabels);
    98. axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
    99. caption = sprintf('Pseudo colored labels, from label2rgb().\nBlobs are numbered from top to bottom, then from left to right.');
    100. title(caption, 'FontSize', captionFontSize);
    101. %======================================================================================================================================================
    102. % MAIN PART IS RIGHT HERE!!!
    103. % Get all the blob properties.
    104. props = regionprops(labeledImage, originalImage, 'all');
    105. % Or, if you want, you can ask for only a few specific measurements. This will be faster since we don't have to compute everything.
    106. % props = regionprops(labeledImage, originalImage, 'MeanIntensity', 'Area', 'Perimeter', 'Centroid', 'EquivDiameter');
    107. numberOfBlobs = numel(props); % Will be the same as we got earlier from bwlabel().
    108. %======================================================================================================================================================
    109. %------------------------------------------------------------------------------------------------------------------------------------------------------
    110. % PLOT BOUNDARIES.
    111. % Plot the borders of all the coins on the original grayscale image using the coordinates returned by bwboundaries().
    112. % bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
    113. subplot(3, 3, 6);
    114. imshow(originalImage);
    115. title('Outlines, from bwboundaries()', 'FontSize', captionFontSize);
    116. axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
    117. % Here is where we actually get the boundaries for each blob.
    118. boundaries = bwboundaries(binaryImage); % Note: this is a cell array with several boundaries -- one boundary per cell.
    119. % boundaries is a cell array - one cell for each blob.
    120. % In each cell is an N-by-2 list of coordinates in a (row, column) format. Note: NOT (x,y).
    121. % Column 1 is rows, or y. Column 2 is columns, or x.
    122. numberOfBoundaries = size(boundaries, 1); % Count the boundaries so we can use it in our for loop
    123. % Here is where we actually plot the boundaries of each blob in the overlay.
    124. hold on; % Don't let boundaries blow away the displayed image.
    125. for k = 1 : numberOfBoundaries
    126. thisBoundary = boundaries{k}; % Get boundary for this specific blob.
    127. x = thisBoundary(:,2); % Column 2 is the columns, which is x.
    128. y = thisBoundary(:,1); % Column 1 is the rows, which is x.
    129. plot(x, y, 'r-', 'LineWidth', 2); % Plot boundary in red.
    130. end
    131. hold off;
    132. %------------------------------------------------------------------------------------------------------------------------------------------------------
    133. % Print out the measurements to the command window, and display blob numbers on the image.
    134. textFontSize = 14; % Used to control size of "blob number" labels put atop the image.
    135. % Print header line in the command window.
    136. fprintf(1,'Blob # Mean Intensity Area Perimeter Centroid Diameter\n');
    137. % Extract all the mean diameters into an array.
    138. % The "diameter" is the "Equivalent Circular Diameter", which is the diameter of a circle with the same number of pixels as the blob.
    139. % Enclosing in brackets is a nice trick to concatenate all the values from all the structure fields (every structure in the props structure array).
    140. blobECD = [props.EquivDiameter];
    141. % Loop over all blobs printing their measurements to the command window.
    142. for k = 1 : numberOfBlobs % Loop through all blobs.
    143. % Find the individual measurements of each blob. They are field of each structure in the props strucutre array.
    144. % You could use the bracket trick (like with blobECD above) OR you can get the value from the field of this particular structure.
    145. % I'm showing you both ways and you can use the way you like best.
    146. meanGL = props(k).MeanIntensity; % Get average intensity.
    147. blobArea = props(k).Area; % Get area.
    148. blobPerimeter = props(k).Perimeter; % Get perimeter.
    149. blobCentroid = props(k).Centroid; % Get centroid one at a time
    150. % Now do the printing of this blob's measurements to the command window.
    151. fprintf(1,'#%2d %17.1f %11.1f %8.1f %8.1f %8.1f % 8.1f\n', k, meanGL, blobArea, blobPerimeter, blobCentroid, blobECD(k));
    152. % Put the "blob number" labels on the grayscale image that is showing the red boundaries on it.
    153. text(blobCentroid(1), blobCentroid(2), num2str(k), 'FontSize', textFontSize, 'FontWeight', 'Bold', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle');
    154. end
    155. %------------------------------------------------------------------------------------------------------------------------------------------------------
    156. % Now, I'll show you a way to get centroids into an N -by-2 array directly from props,
    157. % rather than accessing them as a field of the props strcuture array.
    158. % We can get the centroids of ALL the blobs into 2 arrays,
    159. % one for the centroid x values and one for the centroid y values.
    160. allBlobCentroids = vertcat(props.Centroid); % A 10 row by 2 column array of (x,y) centroid coordinates.
    161. centroidsX = allBlobCentroids(:, 1); % Extract out the centroid x values into their own vector.
    162. centroidsY = allBlobCentroids(:, 2); % Extract out the centroid y values into their own vector.
    163. % Put the labels on the rgb labeled image also.
    164. subplot(3, 3, 5);
    165. for k = 1 : numberOfBlobs % Loop through all blobs.
    166. % Place the blob label number at the centroid of the blob.
    167. text(centroidsX(k), centroidsY(k), num2str(k), 'FontSize', textFontSize, 'FontWeight', 'Bold', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle');
    168. end
    169. %------------------------------------------------------------------------------------------------------------------------------------------------------
    170. % Now I'll demonstrate how to select certain blobs based using the ismember() function and extract them into new subimages.
    171. % Let's say that we wanted to find only those blobs
    172. % with an intensity between 150 and 220 and an area less than 2000 pixels.
    173. % This would give us the three brightest dimes (the smaller coin type).
    174. allBlobIntensities = [props.MeanIntensity];
    175. allBlobAreas = [props.Area];
    176. subplot(3, 3, 7);
    177. histogram(allBlobAreas);
    178. % Get a list of the blobs that meet our criteria and we need to keep.
    179. % These will be logical indices - lists of true or false depending on whether the feature meets the criteria or not.
    180. % for example [1, 0, 0, 1, 1, 0, 1, .....]. Elements 1, 4, 5, 7, ... are true, others are false.
    181. allowableIntensityIndexes = (allBlobIntensities > 150) & (allBlobIntensities < 220);
    182. allowableAreaIndexes = allBlobAreas < 2000; % Take the small objects.
    183. % Now let's get actual indexes, rather than logical indexes, of the features that meet the criteria.
    184. % for example [1, 4, 5, 7, .....] to continue using the example from above.
    185. keeperIndexes = find(allowableIntensityIndexes & allowableAreaIndexes);
    186. % Extract only those blobs that meet our criteria, and
    187. % eliminate those blobs that don't meet our criteria.
    188. % Note how we use ismember() to do this. Result will be an image - the same as labeledImage but with only the blobs listed in keeperIndexes in it.
    189. keeperBlobsImage = ismember(labeledImage, keeperIndexes);
    190. % Re-label with only the keeper blobs kept.
    191. labeledDimeImage = bwlabel(keeperBlobsImage, 8); % Label each blob so we can make measurements of it
    192. % Now we're done. We have a labeled image of blobs that meet our specified criteria.
    193. subplot(3, 3, 7);
    194. imshow(labeledDimeImage, []);
    195. axis image;
    196. title('"Keeper" blobs (3 brightest dimes in a re-labeled image)', 'FontSize', captionFontSize);
    197. elapsedTime = toc;
    198. fprintf('Blob detection and measurement took %.3f seconds.\n', elapsedTime)
    199. %------------------------------------------------------------------------------------------------------------------------------------------------------
    200. % Plot the centroids in the overlay above the original image in the upper left axes.
    201. % Dimes will have a red cross, nickels will have a blue X.
    202. message = sprintf('Now I will plot the centroids over the original image in the upper left.\nPlease look at the upper left image.');
    203. reply = questdlg(message, 'Plot Centroids?', 'OK', 'Cancel', 'Cancel');
    204. % Note: reply will = '' for Upper right X, 'OK' for OK, and 'Cancel' for Cancel.
    205. if strcmpi(reply, 'Cancel')
    206. return;
    207. end
    208. subplot(3, 3, 1);
    209. hold on; % Don't blow away image.
    210. for k = 1 : numberOfBlobs % Loop through all keeper blobs.
    211. % Identify if blob #k is a dime or nickel.
    212. itsADime = allBlobAreas(k) < 2200; % Dimes are small.
    213. if itsADime
    214. % Plot dimes with a red +.
    215. plot(centroidsX(k), centroidsY(k), 'r+', 'MarkerSize', 15, 'LineWidth', 2);
    216. else
    217. % Plot nickels with a blue x.
    218. plot(centroidsX(k), centroidsY(k), 'bx', 'MarkerSize', 15, 'LineWidth', 2);
    219. end
    220. end
    221. %------------------------------------------------------------------------------------------------------------------------------------------------------
    222. % Now use the keeper blobs as a mask on the original image so we will get a masked gray level image.
    223. % This will keep the regions in the mask as original but erase (blacken) everything else (outside of the mask regions).
    224. % This will let us display the original image in the regions of the keeper blobs.
    225. maskedImageDime = originalImage; % Simply a copy at first.
    226. maskedImageDime(~keeperBlobsImage) = 0; % Set all non-keeper pixels to zero.
    227. subplot(3, 3, 8);
    228. imshow(maskedImageDime);
    229. axis image;
    230. title('Only the 3 brightest dimes from the original image', 'FontSize', captionFontSize);
    231. %------------------------------------------------------------------------------------------------------------------------------------------------------
    232. % Now let's get the nickels (the larger coin type).
    233. keeperIndexes = find(allBlobAreas > 2000); % Take the larger objects.
    234. % Note how we use ismember to select the blobs that meet our criteria. Get a binary image with only nickel regions present.
    235. nickelBinaryImage = ismember(labeledImage, keeperIndexes);
    236. % Let's get the nickels from the original grayscale image, with the other non-nickel pixels blackened.
    237. % In other words, we will create a "masked" image.
    238. maskedImageNickel = originalImage; % Simply a copy at first.
    239. maskedImageNickel(~nickelBinaryImage) = 0; % Set all non-nickel pixels to zero.
    240. subplot(3, 3, 9);
    241. imshow(maskedImageNickel, []);
    242. axis image;
    243. title('Only the nickels from the original image', 'FontSize', captionFontSize);
    244. %------------------------------------------------------------------------------------------------------------------------------------------------------
    245. % WE'RE BASICALLY DONE WITH THE DEMO NOW.
    246. elapsedTime = toc;
    247. % Alert user that the demo is done and give them the option to save an image.
    248. message = sprintf('Done making measurements of the features.\n\nElapsed time = %.2f seconds.', elapsedTime);
    249. message = sprintf('%s\n\nCheck out the figure window for the images.\nCheck out the command window for the numerical results.', message);
    250. message = sprintf('%s\n\nDo you want to save the pseudo-colored image?', message);
    251. reply = questdlg(message, 'Save image?', 'Yes', 'No', 'No');
    252. % Note: reply will = '' for Upper right X, 'Yes' for Yes, and 'No' for No.
    253. if strcmpi(reply, 'Yes')
    254. % Ask user for a filename.
    255. FilterSpec = {'*.PNG', 'PNG Images (*.png)'; '*.tif', 'TIFF images (*.tif)'; '*.*', 'All Files (*.*)'};
    256. DialogTitle = 'Save image file name';
    257. % Get the default filename. Make sure it's in the folder where this m-file lives.
    258. % (If they run this file but the cd is another folder then pwd will show that folder, not this one.
    259. thisFile = mfilename('fullpath');
    260. [thisFolder, baseFileName, ext] = fileparts(thisFile);
    261. DefaultName = sprintf('%s/%s.tif', thisFolder, baseFileName);
    262. [fileName, specifiedFolder] = uiputfile(FilterSpec, DialogTitle, DefaultName);
    263. if fileName ~= 0
    264. % Parse what they actually specified.
    265. [folder, baseFileName, ext] = fileparts(fileName);
    266. % Create the full filename, making sure it has a tif filename.
    267. fullImageFileName = fullfile(specifiedFolder, [baseFileName '.tif']);
    268. % Save the labeled image as a tif image.
    269. imwrite(uint8(coloredLabels), fullImageFileName);
    270. % Just for fun, read image back into the imtool utility to demonstrate that tool.
    271. tifimage = imread(fullImageFileName);
    272. imtool(tifimage, []);
    273. end
    274. end
    275. %------------------------------------------------------------------------------------------------------------------------------------------------------
    276. % OPTIONAL : CROP EACH COIN OUT TO A SEPARATE SUB-IMAGE ON A NEW FIGURE.
    277. message = sprintf('Would you like to crop out each coin to individual images?');
    278. reply = questdlg(message, 'Extract Individual Images?', 'Yes', 'No', 'Yes');
    279. % Note: reply will = '' for Upper right X, 'Yes' for Yes, and 'No' for No.
    280. if strcmpi(reply, 'Yes')
    281. % Maximize the figure window.
    282. hFig2 = figure; % Create a new figure window.
    283. hFig2.Units = 'normalized';
    284. hFig2.WindowState = 'maximized'; % Go to full screen.
    285. hFig2.NumberTitle = 'off'; % Get rid of "Figure 1"
    286. hFig2.Name = 'Demo by Image Analyst'; % Put this into title bar.
    287. for k = 1 : numberOfBlobs % Loop through all blobs.
    288. % Find the bounding box of each blob.
    289. thisBlobsBoundingBox = props(k).BoundingBox; % Get list of pixels in current blob.
    290. % Extract out this coin into it's own image.
    291. subImage = imcrop(originalImage, thisBlobsBoundingBox);
    292. % Determine if it's a dime (small) or a nickel (large coin).
    293. if props(k).Area > 2200
    294. coinType = 'nickel';
    295. else
    296. coinType = 'dime';
    297. end
    298. % Display the image with informative caption.
    299. subplot(3, 4, k);
    300. imshow(subImage);
    301. caption = sprintf('Coin #%d is a %s.\nDiameter = %.1f pixels\nArea = %d pixels', ...
    302. k, coinType, blobECD(k), props(k).Area);
    303. title(caption, 'FontSize', textFontSize);
    304. end
    305. %------------------------------------------------------------------------------------------------------------------------------------------------------
    306. % Display the MATLAB "peaks" logo.
    307. logoSubplot = subplot(3, 4, 11:12);
    308. caption = sprintf('A MATLAB Tutorial by ImageAnalyst');
    309. text(0.5,1.15, caption, 'Color','r', 'FontSize', 18, 'FontWeight','b', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle') ;
    310. positionOfLowerRightPlot = get(logoSubplot, 'position');
    311. L = 40*membrane(1,25);
    312. logoax = axes('CameraPosition', [-193.4013, -265.1546, 220.4819],...
    313. 'Box', 'off', ...
    314. 'CameraTarget',[26, 26, 10], ...
    315. 'CameraUpVector',[0, 0, 1], ...
    316. 'CameraViewAngle',9.5, ...
    317. 'DataAspectRatio', [1, 1, .9],...
    318. 'Position', positionOfLowerRightPlot, ...
    319. 'Visible','off', ...
    320. 'XLim',[1, 51], ...
    321. 'YLim',[1, 51], ...
    322. 'ZLim',[-13, 40], ...
    323. 'parent', gcf);
    324. axis(logoSubplot, 'off');
    325. s = surface(L, ...
    326. 'EdgeColor','none', ...
    327. 'FaceColor',[0.9, 0.2, 0.2], ...
    328. 'FaceLighting','phong', ...
    329. 'AmbientStrength',0.3, ...
    330. 'DiffuseStrength',0.6, ...
    331. 'Clipping','off',...
    332. 'BackFaceLighting','lit', ...
    333. 'SpecularStrength',1, ...
    334. 'SpecularColorReflectance',1, ...
    335. 'SpecularExponent',7, ...
    336. 'Tag','TheMathWorksLogo', ...
    337. 'parent',logoax);
    338. l1 = light('Position',[40, 100, 20], ...

    % OPTIONAL : CROP EACH COIN OUT TO A SEPARATE SUB-IMAGE ON A NEW FIGURE.
    message = sprintf('Would you like to crop out each coin to individual images?');
    reply = questdlg(message, 'Extract Individual Images?', 'Yes', 'No', 'Yes');
    % Note: reply will = '' for Upper right X, 'Yes' for Yes, and 'No' for No.
    if strcmpi(reply, 'Yes')
        % Maximize the figure window.
        hFig2 = figure;    % Create a new figure window.
        hFig2.Units = 'normalized';
        hFig2.WindowState = 'maximized'; % Go to full screen.
        hFig2.NumberTitle = 'off'; % Get rid of "Figure 1"
        hFig2.Name = 'Demo by Image Analyst'; % Put this into title bar.

        for k = 1 : numberOfBlobs        % Loop through all blobs.
            % Find the bounding box of each blob.
            thisBlobsBoundingBox = props(k).BoundingBox;  % Get list of pixels in current blob.
            % Extract out this coin into it's own image.
            subImage = imcrop(originalImage, thisBlobsBoundingBox);
            % Determine if it's a dime (small) or a nickel (large coin).
            if props(k).Area > 2200
                coinType = 'nickel';
            else
                coinType = 'dime';
            end
            % Display the image with informative caption.
            subplot(3, 4, k);
            imshow(subImage);
            caption = sprintf('Coin #%d is a %s.\nDiameter = %.1f pixels\nArea = %d pixels', ...
                k, coinType, blobECD(k), props(k).Area);
            title(caption, 'FontSize', textFontSize);
        end

        %------------------------------------------------------------------------------------------------------------------------------------------------------
        % Display the MATLAB "peaks" logo.
        logoSubplot = subplot(3, 4, 11:12);
        caption = sprintf('A MATLAB Tutorial by ImageAnalyst');
        text(0.5,1.15, caption, 'Color','r', 'FontSize', 18, 'FontWeight','b', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle') ;
        positionOfLowerRightPlot = get(logoSubplot, 'position');
        L = 40*membrane(1,25);
        logoax = axes('CameraPosition', [-193.4013, -265.1546, 220.4819],...
            'Box', 'off', ...
            'CameraTarget',[26, 26, 10], ...
            'CameraUpVector',[0, 0, 1], ...
            'CameraViewAngle',9.5, ...
            'DataAspectRatio', [1, 1, .9],...
            'Position', positionOfLowerRightPlot, ...
     

    🎉3 参考文献

    文章中一些内容引自网络,会注明出处或引用为参考文献,难免有未尽之处,如有不妥,请随时联系删除。

    [1]马寅.基于CCD的图像特征提取与识别[D].东北大学,2012.DOI:10.7666/d.J0120301.

    [2]王妞,康辉英.基于图像检测的船舶特征分割与提取优化算法[J].舰船科学技术, 2018(4X):3.DOI:CNKI:SUN:JCKX.0.2018-08-049.

    [3]尹聪.彩色图像人脸检测与特征提取认证[J].信息技术与信息化, 2009.DOI:JournalArticle/5af35bd8c095d718d80b8d86.

    [4]罗文辉,王三武.基于面积和结构特征的水表图像二步分割方法[J].武汉理工大学学报:信息与管理工程版, 2006, 28(5):4.DOI:10.3963/j.issn.1007-144X.2006.05.014.

    🌈4 Matlab代码实现

  • 相关阅读:
    块设备和总线
    CesiumJS【Basic】- #006 浏览器控制台查看位置角度
    104. 二叉树的最大深度 | 层序遍历 | 遍历 | 子问题 | TypeScript
    mpu6050姿态解算与卡尔曼滤波(5)可应用于51单片机的卡尔曼滤波器
    Python数据分析案例
    git连接GitHub上的远程仓库
    Memcached 未授权访问漏洞验证
    Elasticsearch(016):es常见的字段映射类型之对象类型(object)
    【JAVASE】String类
    Java8 Stream API 基础操作
  • 原文地址:https://blog.csdn.net/Ke_Yan_She/article/details/133150592