MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   Matlab-前景分割-图像处理 (https://www.labfans.com/bbs/showthread.php?t=22189)

poster 2019-11-27 18:11

Matlab-前景分割-图像处理
 
我正在尝试使用前景分割对图像进行分割:

有谁知道我该怎么做才能得到我的结果。我一直在努力争取任何帮助。

Original image:

[URL="https://i.stack.imgur.com/8UT8H.png"][IMG]https://i.stack.imgur.com/8UT8H.png[/IMG][/URL]

My result:

[URL="https://i.stack.imgur.com/8AdiM.png"][IMG]https://i.stack.imgur.com/8AdiM.png[/IMG][/URL]

And I am trying to produce this (Desired result):

[URL="https://i.stack.imgur.com/ZW7bR.png"][IMG]https://i.stack.imgur.com/ZW7bR.png[/IMG][/URL]

码:

`clc; % Clear the command window. close all; % Close all figures (except those of imtool.) clear; % Erase all existing variables. Or clearvars if you want. %=============================================================================== % Get the name of the image the user wants to use. baseFileName = 'in000439.png'; % Get the full filename, with path prepended. folder = []; % Determine where demo folder is (works with all versions). fullFileName = fullfile(folder, baseFileName); %=============================================================================== % Read in a demo image. grayImage = imread(fullFileName); % Get the dimensions of the image. % numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image. [rows, columns, numberOfColorChannels] = size(grayImage) if numberOfColorChannels > 1 % It's not really gray scale like we expected - it's color. % Use weighted sum of ALL channels to create a gray scale image. grayImage = rgb2gray(grayImage); % ALTERNATE METHOD: Convert it to gray scale by taking only the green channel, % which in a typical snapshot will be the least noisy channel. % grayImage = grayImage(:, :, 2); % Take green channel. end % Display the image. subplot(2, 2, 1); imshow(grayImage, []); % Binarize the image by thresholding. mask = grayImage < 100; % Display the mask image. % Get rid of blobs touching the border. mask = imclearborder(mask); % Extract just the largest blob. mask = bwareafilt(mask, 1); % Display the mask image. subplot(2, 2, 4); imshow(mask); % Get rid of black islands (holes) in struts without filling large black areas. subplot(2, 2, 4); mask = ~bwareaopen(~mask, 1000); imshow(mask); drawnow;`

[url=https://stackoverflow.com/q/59059642]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 09:37

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.