필터 지우기
필터 지우기

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'));

추가 답변 (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