'dec2bin' produce error when converting rounded float number
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (2)
Sean de Wolski
le 22 Juil 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.
Fangjun Jiang
le 22 Juil 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Numeric Types dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!