How to run the following function on GPU or make it Faster
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have following MATLAB function It is very slow it takes so much time,it takes 5 seconds to run, but i want to run it in miliseconds,
Can anyone Help me running this code on GPU. I have also Attached the Dataset Below
[valueestimationimage ] = Parameterestimate(Batchdata)
fig=figure; set(fig,'visible','off');
h=histogram(Batchdata,10000,"BinMethod","sturges",'BinWidth',1,'BinLimits',[1 10000]);
sumofbins=max(h.Values);
% size_MP=round(10/100*sumofbins);
size_MP=round(10/100*sumofbins);
ValueofHistogram= h.Values;
Bindata=h.Data;
Binedges=h.BinEdges;
Binedges(end) = Inf;
deleted_data_idx = false(size(Bindata));
for i=1: length(ValueofHistogram)
if ValueofHistogram(i)<size_MP;
deleted_data_idx(Bindata >= Binedges(i) & Bindata < Binedges(i+1)) = true;
end
end
close(fig);
Bindata(deleted_data_idx) = [];
fig=figure; set(fig,'visible','off');
Freq_Data = Bindata;
h = histogram(Freq_Data, 10000, "BinMethod", "sturges", 'BinWidth', 1, 'BinLimits', [1 10000]);
[N, Edges, Bin] = histcounts(Freq_Data, 10000, "BinMethod", "sturges", 'BinWidth', 1, 'BinLimits', [1 10000]);
Retain = N > max(N) / 3.5;
% Find the bin indices that satisfy the condition
FindBins = find(Retain);
% Update RetainDataLv based on the valid bin indices
RetainDataLv = ismember(Bin, FindBins);
% Apply the logical indexing to retrieve the corresponding data
Bindata = Freq_Data(RetainDataLv);
close(fig);
Bindata=round(Bindata).';
[GC, GR] = groupcounts(Bindata) ;
countThresh =30 ; % change this untill you see that the data is fully denoised
denoisedData = Bindata(ismember(Bindata, GR(GC>countThresh))) ;
% incomingdata= denoisedData.';
if isempty(denoisedData)
incomingdata=Bindata.';
else
incomingdata=denoisedData.';
end
[row, column] = size(incomingdata);
for eachrow=1:row
if column>=1000
% buffered(eachrow,:) = buffer(incomingdata, 1000);
groupsize = 1000;
sig = incomingdata(:);
if isempty(sig)
error('signal is empty, cannot buffer it');
end
sigsize = numel(sig);
fullcopies = floor(groupsize ./ sigsize);
sig = repmat(sig, 1+fullcopies, 1);
sigsize = numel(sig);
leftover = mod(sigsize, groupsize);
if leftover ~= 0
sig = [sig; sig(1:groupsize-leftover)];
end
buffered = buffer(sig, groupsize);
else
targetsize = 1000;
sizeofincomingdata = column;
nrep = targetsize / sizeofincomingdata;
fullrep = floor(nrep);
leftover = targetsize - fullrep * sizeofincomingdata;
buffered=[repmat(incomingdata(eachrow,:), 1, fullrep), incomingdata(1:leftover)];
sig=buffered.';
end
end
signal=sig.';
[numImages, lenImage] = size( signal);
imbg = false(10000,lenImage); % background "color"
imfg = ~imbg(1,1); % forground "color"
imSizeOut=[10000 lenImage];
% ImageSize
for k= 1:numImages
imData = round( signal(k,:)); % get pattern
[~,Y] = meshgrid(1:lenImage,1:10000); % make a grid
% black and white image
BW = imbg;
BW(Y==imData)=imfg;
valueestimation=imbinarize(imresize(uint8(BW),imSizeOut));
% convert to uint8 (0 255)
valueestimationimage = im2uint8(valueestimation);
% resize (from 1000x1000)
SE=strel('disk',2);
BW=imdilate(BW,SE);
BW=imbinarize(imresize(uint8(BW),imSizeOut));
% convert to uint8 (0 255)
imoriginalestimate = im2uint8(BW);
end
end
0 commentaires
Réponses (1)
Lakshya
le 19 Juin 2023
Hi,
you can refer to this previous MATLAB answer
Also you can refer to this documentation
Hope this helps.
Voir également
Catégories
En savoir plus sur GPU Computing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!