'dec2bin' produce error when converting rounded float number

9 views (last 30 days)
I tried to load an image, scale and output the binary code of each pixel. 'dec2bin' requires integer smaller than 2^52, so I rounded each floating element and then did the conversion, however the error keeps jumping out saying: ----------------------------------------------
*??? Error using ==> dec2bin at 33
D must be a non-negative integer smaller than 2^52.
Error in ==> image_ge_v2 at 12
v = dec2bin(iresize_r(i),9);*
----------------------------------------------
It is for sure that the elements in the matrix are smaller than 256.
Here's the segment of my code:
----------------------------------------------
icolour = imread('iig_v22.jpg');
icolour_s = imresize(icolour,[200 200]);
igray = rgb2gray(icolour_s);
igray = double(igray);
A = fopen('image.txt','wt');
iresize = imresize(igray,[60 60]);
iresize_r = round(iresize);
for i = 1:numel(iresize_r)
v = dec2bin(iresize_r(i),9);
end
------------------------------------------------
Please give me some hint!
Thanks a lot

Answers (2)

Sean de Wolski
Sean de Wolski on 22 Jul 2011
icolour = imread('peppers.png');
icolour_s = imresize(icolour,[200 200]);
igray = rgb2gray(icolour_s);
igray = double(igray);
iresize = imresize(igray,[60 60]);
iresize_r = round(iresize);
for i = 1:numel(iresize_r)
v = dec2bin(iresize_r(i),9);
end
I get no error doing this with a stock image.
  1 Comment
Jeff
Jeff on 26 Jul 2011
well the trick is here, I also tried different image some of them are fine but others produce error !

Sign in to comment.


Fangjun Jiang
Fangjun Jiang on 22 Jul 2011
We don't have your data so probably won't re-produce your error. You could check the value of i when the error happened and then check the value of iresize_r(i).
Once your problem is solved, you can use dec2bin(iresize_r,9) without the for-loop.

Community Treasure Hunt

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

Start Hunting!