How to save data as image as one pixel using MATLAB

1 visualizzazione (ultimi 30 giorni)
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);
tempdir=mkdir('DATASET1');
classdir=mkdir('DATASET1','OneClass');
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)
mkdir(dataDirectory,labelStr);
end
end
%% 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;
BW(Y==imData)=imfg;
% resize (from 1000x1000)
BW=imbinarize(imresize(uint8(BW),imSizeOut));
% 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));
imwrite(im,im_FullFilename);
end

Risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by