How to save data as image as one pixel using MATLAB

2 views (last 30 days)
Hello everyone, i hope you are doing well.
I am going to save the data as image format i have written the following code as one of the answer on MATLAB.
The dataset is Dats.mat file the Original data first row is
  • Original Data.jpg
The Image generated from the data is
  • ImagefromData.jpg
The save is generated same like the data but when i compared the values the first value of the dataset is 173 as shown in
  • FirstValue.PNG
But when i look at the first value of image it is 173.5 and 172.5
  • Firstvalueofimage.PNG
but the value should be only 173
How can i modified this code to save 173 value as 173 pixel value
Can anybody help me in this
labels1000= repelem(eye(1,1),1000,1);
dataDirectory = fullfile('C:\Users\DELL\Documents\MATLAB\Examples\R2021b\phased\ModClassificationOfRadarAndCommSignalsExample\NewDataset\DatasetGeneration\DATASET1\SixClass');
disp("Data file directory is " + dataDirectory)
[labelNums,~,labelIdx] = unique(labels1000,'rows');
labelStrs = {'Class'};
%% make the folders
for ii = 1:numel(labelStrs)
labelStr = labelStrs{ii};
if ~isfolder(labelStr)
%% create grayscale shapes that resemble the data
[numImages, lenImage] = size(Dataset1000);
imSz = 1000; % assuming images are 1000x1000
imbg = false(imSz); % background "color"
imfg = ~imbg(1,1); % forground "color"
imSizeOut=[1000 1000]; % ImageSize
for imNum = 1:numImages
imData = round(Dataset1000(imNum,:)); % get pattern
[~,Y] = meshgrid(1:imSz); % make a grid
% black and white image
BW = imbg;
% resize (from 1000x1000)
% convert to uint8 (0 255)
im = im2uint8(BW);
%im = flipud(im);
folderName = labelStrs{labelIdx(imNum)};
im_FullFilename = fullfile(dataDirectory,folderName,sprintf('imageclass_%06g.png',imNum));

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by