im2bw matlab
时间: 2023-10-16 17:33:26 浏览: 87
In MATLAB, the `im2bw` function is used to convert an image to binary format. The function takes an input grayscale or RGB image and a threshold value, and outputs a binary image where pixel values are either 0 or 1 based on whether they are below or above the threshold value.
Here's an example of how to use `im2bw`:
```matlab
% Read in an image
img = imread('example.jpg');
% Convert to grayscale
gray_img = rgb2gray(img);
% Convert to binary using a threshold value of 0.5
binary_img = im2bw(gray_img, 0.5);
% Display the binary image
imshow(binary_img);
```
In this example, we first read in an RGB image and convert it to grayscale. We then use `im2bw` to convert the grayscale image to binary format using a threshold value of 0.5. Finally, we display the resulting binary image using `imshow`.
阅读全文