'dec2bin' produce error when converting rounded float number
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (2개)
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.
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Precision에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!