Convert color images to binary images, which can be implemented in matlab 7 and not run in 2014a
2 次查看(过去 30 天)
显示 更早的评论
codes are as this
clc;
clear all;
close all;
B = imread('1.jpg');
A= rgb2gray(B);
[m,n]=size(A);
for i=1:1:m
for j=1:1:n
if(A(i,j)>110)
A(i,j)=255;
end
end
end
imwrite(A,'1.jpg')
The picture has been placed in the running folder, but the result of running in 2014a is
错误使用 rgb2gray>parse_inputs (line 80)
MAP must be a m x 3 array.
出错 rgb2gray (line 35)
X = parse_inputs(X);
出错 tuxiangchuli (line 6)
A= rgb2gray(B);
>>
why?thanks a lot!
0 个评论
回答(1 个)
Image Analyst
2020-8-9
Only convert to gray scale if the image is definitely RGB. Make sure you use all 3 outputs when using size() with images. See Steve's blog.
And no for loop needed:
B = imread('1.jpg');
[rows, columns, numberOfColorChannels] = size(B);
if numberOfColorChannels == 3
A = rgb2gray(B); % Convert to gray scale.
else
A = B; % It's already gray scale so no conversion needed.
end
mask = A > 110
A(mask) = 255;
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!