matlab bernsen
时间: 2023-10-16 07:16:27 浏览: 26
Bersen thresholding is a method used in image processing to separate objects from the background. In Matlab, this can be achieved using the `bernsen` function in the Image Processing Toolbox.
The syntax for using the `bernsen` function is as follows:
```
J = bernsen(I, [m n], contrast);
```
where `I` is the input grayscale image, `[m n]` is the size of the local window used for thresholding, and `contrast` is the contrast threshold used for determining the threshold value.
The `bernsen` function calculates the threshold value for each pixel in the image based on the local window around that pixel. If the difference between the maximum and minimum pixel values in the local window is less than the contrast threshold, the threshold value is set to the midpoint of the pixel values in the window. Otherwise, the threshold value is set to the local minimum pixel value plus half of the difference between the maximum and minimum pixel values.
Here is an example of applying Bernsen thresholding to an image in Matlab:
```
I = imread('example_image.jpg');
J = bernsen(I, [15 15], 20);
imshow(J);
```
This will apply Bernsen thresholding with a local window size of 15x15 and a contrast threshold of 20 to the input image `example_image.jpg` and display the thresholded image.