0
votes

i have problem in converting a matrix of type double to image.iam using imwrite for this but each time, the error is too many input arguments. the matrix has values from 0 to 255 but the type is double. i used imread to open the image, then converted it to binary and then used the command double and tried to convert it back into image. i need the binary form in my fyp and then convert it back to image. how is it possible? if anyone has a solution, kindly help me out. thanks!

3

3 Answers

1
votes

Use this code:

I = imread('test.jpg');
b = dec2bin(I); % b becomes vector
% some actions with binary vector
du = bin2dec(b);
du = reshape(du,size(I)); % converting vector du to 3d Image array 
imwrite(uint8(du), 'du.jpg'); %save our du to file du.jpg

I = imread('du.jpg'); %test if it saved correctly
imshow(du) 
2
votes

You can use im2double to convert from uint8 values to double values. For the inverse, you can use im2uint8.

0
votes

If you use java to call matlab function(java sends byte array as input image), first of all convert matrix to unsigned 8 bit integer:

m1 = typecast(arr, 'uint8');

After set input as unsigned integer, you can use those pixel values as RGB in the range (0, 255). If you want to use some filter like conv2, you must convert unsigned array to image double precision. that can be so:

m2 = im2double(m1);

Applying convolution generates an output as double precision(between 0-1). After that point, if you want to get unsigned values, you must use that:

m3 = im2uint8(m2);

Specially when you call matlab from java, typecasting input array to uint8 is very crucial, because matlab receives java byte array as signed int initially. Solving that was very painful, so tracking that conversion steps may be helpful!