How to convert vectors to their image?

12 次查看(过去 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'));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by