필터 지우기
필터 지우기

'dec2bin' produce error when converting rounded float number

조회 수: 4 (최근 30일)
Jeff
Jeff 2011년 7월 22일
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

답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 7월 22일
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
Jeff
Jeff 2011년 7월 26일
well the trick is here, I also tried different image some of them are fine but others produce error !

댓글을 달려면 로그인하십시오.


Fangjun Jiang
Fangjun Jiang 2011년 7월 22일
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!

Translated by