Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

1 visualizzazione (ultimi 30 giorni)
% 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 Commenti
Devanshee Tanna
Devanshee Tanna il 7 Set 2014
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!

Risposte (1)

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

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by