Info

此问题已关闭。 请重新打开它进行编辑或回答。

Can anyone please help me correct the error in this program for generating a binary image from rgb image?

1 次查看(过去 30 天)
% plot
r = 1;
t=0:0.002:1;
a=zeros(500);
s=zeros(500);
for i=1:500
a(i)= deg2rad(t(i)*90);
s(i) = (r*pi*t(i)) / 2;
xc(i) = r * sin(a(i));
yc(i) = r * sin(a(i));
x(i) = xc(i) + ( s(i) * sin(a(i)));
y(i) = yc(i) - ( s(i)* cos(a(i)));
plot(x,y)
end
% rasterize it to an 50 row x 100 col image;
nRow = 50;
nCol = 100;
xNode = linspace(min(x),max(x),nCol);
yNode = linspace(min(y),max(y),nRow);
yInterp = interp1(x,y,xNode,'cubic','extrap');
xi = 1:nCol;
yi = round(interp1(yNode,1:nRow,yInterp,'linear','extrap'));
im = accumarray([yi(:), xi(:)],1,[nRow,nCol]);
imagesc(im);
% define threshold frequency
threshold=125;
% obtain the image size
[M,N,clrs]=size(im);
M=10
N=10
clrs=2
%convert the image into type double for matlab operations
tempimage=double(im);
% create space for the lightened image
filteredimage = zeros(M,N,2);
% compute the average of all color intensities
temp1=(tempimage(:,:,1)+ tempimage(:,:,2))/2;
% compare this with the threshold
temp2=temp1 > threshold;
%convert it to a range from 0-255
filteredimage(:,:,1)=255 * double(temp2);
filteredimage(:,:,2)=filteredimage(:,:,1);
%
newimage=uint8(filteredimage);
figure
image(newimage);
axis off

回答(1 个)

yonatan gerufi
yonatan gerufi 2014-9-10
if you have image processing toolbox you can use " im2bw " function.

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by