hi friends i need a Matlab code to generate binary image by giving input matrix values. then i should convert it to grayscale image. for grayscale image direct values shouldnot be given. first a binary image should be generated and then it should be converted to grayscaale. Also is there any code to convert text to 256 bit binary number and 256 bit number to text.
hi.
1.If you don't want to use matlab fuctions for this purpose the following code generate a grayscle image to binary (note: threshold value is arbitary!)
%-------------------------------------------------
clc
clear all
close all
img=imread('your image');
[R C]=size(img);
img_bin=zeros(R,C);
threshold= 128;
[h_rows h_cols] = find(img >= threshold);
[l_rows l_cols] = find(img < threshold);
for i=1:size(h_rows,1)
img_bin(h_rows(i,, h_cols(i, )=1;
end
for i=1:size(l_rows,1)
img_bin(l_rows(i,, l_cols(i, )=0;
end
figure(1)
subplot(1,2,1)
imshow(img);
title( 'Original Image' );
hold on
subplot(1,2,2)
imshow(img_bin);
title( 'Binary Image' );
hold on
%------------------------------------------
2.for converting the binary image (which obtained above) to grayscle, i don't sure but this is the only way you should know that the pixel values before converting to binaty!!!