フィルターのクリア

Text to Image conversion

4 ビュー (過去 30 日間)
Lalitha Sivaraman
Lalitha Sivaraman 2013 年 9 月 27 日
回答済み: Image Analyst 2013 年 9 月 27 日
when i try to run this code with text file contain binary values that i attach..,
% Text to image conversion
% % Open the txt file
fid = fopen('Big_Picture.txt', 'r');
% Scann the txt file
img = fscanf(fid, '%x', [1 inf]);
% Close the txt file
fclose(fid)
% restore the image
outImg = reshape(img,[128 128]);
outImg = outImg';
figure, imshow(outImg,[])
it shows error :
Error using reshape
To RESHAPE the number of elements must not change.
Error in hexnew (line 10)
outImg = reshape(img,[128 128]);
pls mention What mistake that i had done ??

回答 (2 件)

Walter Roberson
Walter Roberson 2013 年 9 月 27 日
Why are you assuming that the file has exactly 128 * 128 hex numbers in it? Did you check length(img) ?
  2 件のコメント
Lalitha Sivaraman
Lalitha Sivaraman 2013 年 9 月 27 日
image size is 256x120
Walter Roberson
Walter Roberson 2013 年 9 月 27 日
Could you show an example text line?
If the image is 256 x 120 and you were to read it in successfully, then you are not going to be able to reshape it as 128 * 128 . You would have more hope if the image had been 256 x 128 instead of 256 x 120: in such a case there might be a reason why two adjacent elements in the input should become one element in output.

サインインしてコメントする。


Image Analyst
Image Analyst 2013 年 9 月 27 日
Try
img = fscanf(fid, '%x', [256, 120]);
then
resizedImage = imresize(img, [128, 128]);

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by