フィルターのクリア

How to convert vectors to their image?

9 ビュー (過去 30 日間)
Yamini Nibhanupudi
Yamini Nibhanupudi 2018 年 6 月 30 日
コメント済み: Yamini Nibhanupudi 2018 年 6 月 30 日
I have a vector of 1x10000 (contains only 0s and 1s) which I need to convert into a 100x100 and then 1200x900 image. The following is the code I use.
% the vector is present in an excel file.
filename = 'D:\Winter 2018\project\Dataset\CSV files\csv_files\Object1_set9\Prediction.xlsx';
sheet = 1;
xlRange = 'A2:A10001';
data = xlsread(filename,sheet,xlRange);
image = double(reshape(data,100,100)); %devectorizing the 1x10000 vector
Im = imresize(image,[1200,900]); % resizing it to a 1200x900 image
dir = strcat('D:\Winter 2018\project\Dataset\Results_70\GTP_GBT\');
saveas(gcf,strcat(dir,('Image')),'jpg'); %saving the current image in jpg format
figure,imshow(image); % preview of the current image
I face two problems with this code. First, I am unable to get the image in 1200x900 dimension. It is saved with some random dimensions. Second, my image has a lot of white space around it when it is saved on the computer. But, that white space is not seen in the preview. This means that the image is not saved as it is shown in the preview. Please let me know what is my error in this code.

採用された回答

Walter Roberson
Walter Roberson 2018 年 6 月 30 日
You do not preview anything. You do not draw anything. gcf will refer to whatever happens to be on the figure, or will create an empty figure if nothing is open.
You should
  1. use a different variable name rather than "image", because image() is a key MATLAB routine to display images; at the very least you are confusing readers
  2. Do not use saveas(): use imwrite()
imwrite(RenamedImageVariable, fullfile(dir, 'Image.jpg'));
  1 件のコメント
Yamini Nibhanupudi
Yamini Nibhanupudi 2018 年 6 月 30 日
Thank you. It works.

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

その他の回答 (0 件)

カテゴリ

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