Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Devanshee Tanna
Devanshee Tanna 2014 年 9 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
% 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
  2 件のコメント
Devanshee Tanna
Devanshee Tanna 2014 年 9 月 7 日
It is, I did not post the code in a proper format, hence the repost. If you could help me get the required output of a binary image, I shall be grateful to u! Ur suggestion of replacing imagesc(im) with image()/imshow() could not give me that.. if you could verify and tell me? thanks!

回答 (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