Info
This question is closed. Reopen it to edit or answer.
Can anyone please help me correct the error in this program for generating a binary image from rgb image?
1 view (last 30 days)
Show older comments
% 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 Comments
Image Analyst
on 7 Sep 2014
Isn't this a duplicate of your first post http://www.mathworks.com/matlabcentral/answers/153903-hey-i-have-written-this-code-for-conversion-of-plot-to-rgb-image-followed-by-conversion-to-binary-i???
Answers (1)
yonatan gerufi
on 10 Sep 2014
if you have image processing toolbox you can use " im2bw " function.
0 Comments
This question is closed.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!