Image threshold Segmentation matlab version __matlab

Source: Internet
Author: User
Image threshold Segmentation is a very simple algorithm.
The image pixel, greater than the threshold, is considered a target, and less than the threshold is considered a background.

The threshold segmentation that we are experiencing now needs to accomplish several functions as follows:
1, the basic threshold value segmentation:
is greater than the threshold, it is considered a target;
2, low pixel value is considered to be the target, that is, to reverse the unequal number
For image pixel, less than threshold, considered to be the target, or greater than the threshold, it is considered a background.
3, the possible threshold segmentation image is just a marker image
After segmenting the marked image, it is necessary to display the segmented target area on the original image.
This requires you to enter the original image
The original image may be a grayscale image, or it may be a color image
4, multiple thresholds for segmentation
Output the result of dividing each threshold

It took two hours, complete the single threshold segmentation completed the function 1, 2, 3; The function 4 is also integrated, but it feels like this, the code is too convoluted, and there is a certain amount of code redundancy, so separate it into a separate function, through the invocation of single threshold segmentation implementation.

Implementation of Feature 2: Add a bias tag bias
If 1, the normal condition, greater than the threshold, is considered a target
IS-1, the vice versa.
For comparison purposes: Bias*image>bias*thresh is common to two situations


% threshold segmentation for tagged images
%
% mark image with pixel value greater than thresh, think Shivi spot, otherwise think is not disease spot
%
Enter
Image of threshold segmentation by% image
% Thresh Split threshold value
% bias split bias, defaults to 1
% bias = + 1 greater than threshold 1, less than threshold 0
% bias =-1 greater than threshold 0, less than threshold 1
% bgimage background image, the area identified on image as the target is reserved, while the identified as background deletes
% default image for threshold segmentation
%
Output
% Labbinaryimage identifies disease spot image, binary image
% labsrcimage mark on background image to identify disease spot area
%
% [Labbinaryimage,labsrcimage] = threshsegement (image, Thresh);
% [Labbinaryimage,labsrcimage] = threshsegement (image, Thresh, bias);
% [Labbinaryimage,labsrcimage] = threshsegement (image, Thresh, bias, bgimage);
%
% 2007-11-08
%
function [Labbinaryimage,labsrcimage] = threshsegement (image, Thresh, Varargin)
Iptchecknargin (2, 4, Nargin, mfilename); % Detection Input Parameters number
Iptcheckinput (image, {' numeric '}, {' 2d ', ' real ', ' nonsparse '}, Mfilename, ' image ', 1);
Iptcheckinput (Thresh, {' numeric '}, {' Row ', ' nonempty ', ' real '}, Mfilename, ' Thresh ', 2);
Thresh = Thresh (1); % takes only the first threshold
bias = 1; % offset, defaults to 1
if (nargin> 2)% specifies bias
Bias = varargin{1};
End
if (bias~ = 1)% bias allows only values 1 and-1
bias =-1;
End
Image = double (image); % Type conversions
Iptcheckinput (bias, {' numeric '}, {' Row ', ' nonempty ', ' Integer '}, Mfilename, ' bias ', 3);


if (nargin> 3)% displays the background image
Bgimage = varargin{2};
if (Size (bgimage, 1) ~ = Size (image, 1)) | | (Size (bgimage, 2) ~ = Size (image, 2))
The error (' Background image size needs to be exactly the same as the split image. ') ;
End
Else
Bgimage = image; % defaults to image images with threshold segmentation
End
Iptcheckinput (bgimage, {' numeric '}, {' Real ', ' nonsparse '}, Mfilename, ' Bgimage ', 4);


% threshold segmentation, generating two tagged images
Labbinaryimage = zeros (size (image)); % spot area on binary image

Labbinaryimage (Find (bias*image> = bias*thresh)) = 1;


if (nargout> 1)% outputs the background image to identify the diseased spot area
For cur = 1:size (bgimage, 3) is labeled for each plane, and grayscale images and color images can be
Curlabsrcimage = Bgimage (:,:, cur);
Curlabsrcimage (Find (bias*image<bias*thresh)) = 0;
Labsrcimage (:,:, cur) = curlabsrcimage;
End
End


But there is also a problem, the border situation. That is, the Bias*image=bias*thresh pixel category. Bias the collation rules differ slightly from the different values. For example, collation rules: Bias*image>bias*thresh,bias=1 when the value is greater than the threshold is considered to be the target pixel, bias=-1 is less than or equal to the threshold value is considered to be the target pixel. The difference is an equal sign. not be consistent.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.