필터 지우기
필터 지우기

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
  댓글 수: 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