![]() |
如何在MATLAB中的索引图像上使用Graythresh?
I = imread('coins.png'); level = graythresh(I); BW = im2bw(I,level); imshow(BW) 上面是MATLAB文档中使用灰度图像的示例。如何使它与索引图像(如[URL="https://i.stack.imgur.com/OsccS.png"][IMG]https://i.stack.imgur.com/OsccS.png[/IMG][/URL]在[URL="https://stackoverflow.com/questions/2586539/why-do-i-get-an-all-black-grayscale-image-when-i-load-this-png-in-matlab"]这篇文章中[/URL] ?
[B]回答:[/B] 您可以先使用[URL="http://www.mathworks.com/access/helpdesk/help/toolbox/images/ind2gray.html"]IND2GRAY[/URL]函数将索引图像及其[URL="http://www.mathworks.com/access/helpdesk/help/toolbox/images/ind2gray.html"]色彩[/URL]图转换为灰度图像: [X,map] = imread('SecCode.php.png'); %# Read the indexed image and colormap grayImage = ind2gray(X,map); %# Convert to grayscale image 然后,您可以应用上面的代码: level = graythresh(grayImage); %# Compute threshold bwImage = im2bw(grayImage,level); %# Create binary image imshow(bwImage); %# Display image [B]编辑:[/B] 如果您想对任何类型的图像都采用这种通用方法,则可以采用以下一种方法: %# Read an image file: [X,map] = imread('an_image_file.some_extension'); %# Check what type of image it is and convert to grayscale: if ~isempty(map) %# It's an indexed image if map isn't empty grayImage = ind2gray(X,map); %# Convert the indexed image to grayscale elseif ndims(X) == 3 %# It's an RGB image if X is 3-D grayImage = rgb2gray(X); %# Convert the RGB image to grayscale else %# It's already a grayscale or binary image grayImage = X; end %# Convert to a binary image (if necessary): if islogical(grayImage) %# grayImage is already a binary image bwImage = grayImage; else level = graythresh(grayImage); %# Compute threshold bwImage = im2bw(grayImage,level); %# Create binary image end %# Display image: imshow(bwImage); 除某些离群值(例如[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/imread.html#f25-721031"]TIFF图像的备用颜色空间[/URL] )外,这应涵盖[I]大多数[/I]图像类型。 [url=https://stackoverflow.com/questions/2587110]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 04:57。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.