use gpu for image processing
1 回表示 (過去 30 日間)
古いコメントを表示
MatlabEnthusiast
2021 年 6 月 11 日
コメント済み: MatlabEnthusiast
2021 年 6 月 20 日
hello, I have created about 1500 images on disk. I process them, store the results as mat files on disk, say image1_result1.mat, then read these results from another function which also creates a mat file after its processing say image1_result2.mat.
so i do these iteratively for all the 1500 images. But i noticed that my pc, despite having gpu, is using the cpu. In fact GPU used by matlab is 0% while cpu oscillates between 24% and about 94%.
Now am wondering if there's a way to execute these operations using the gpu in matlab. if so how best can I modify the code.
Structure of the main script that is looping is like this:
for i=1:total_images % do this for all images
[p, n, e] = fileparts(image_name);
image = image_name; % 'Image1.jpg';
param_one = p1;
param_two = p2;
% generate params for algorithm 1 from the image
generateParams(image, param_one); % saves results in image1_result.mat
% create corresponding database for the image
create_data(image, param_two); % reads param_two and others from image1_result.mat
% get the re-created image using algorithm
create_final(image_name, param_one); % stores results in image1_final.mat
end
for i=1:total_images
load('imagei_final'); % loads final results of image i from disk for calculations
use these results to calculate statistics.
end
How best can i convert this to a gpu executable algorithm to have faster performance, if possible? thanks.
3 件のコメント
Joss Knight
2021 年 6 月 14 日
Sorry, it's not possible to know without seeing your code. Every function that has gpuArray input will have gpuArray outputs, so typically you only need to convert your initial input data; unless you are loading or generating new data inside your function. And then if you are using certain functions in Deep Learning and some other toolboxes you may find that no changes are needed to leverage the GPU. So we can't say for sure.
採用された回答
Walter Roberson
2021 年 6 月 13 日
generateParams(image, param_one); % saves results in image1_result.mat
% create corresponding database for the image
create_data(image, param_two); % reads param_two and others from image1_result.mat
I recommend that you avoid the trip to the file system if you want to optimize your code.
image1_result = generateParams(image_name, param_one);
% create corresponding database for the image
image1_data = create_data(image_name, param_two, image1_result);
create_final(image_name, param_one, image1_data)
(and do not use image as a variable name, as image() is a fundamental graphics function.)
image1_result and image1_data could use gpuArray as needed.
Since image1_result could be a struct, you could store the image_name as part of it and so not need to pass it to the other two functions. Also since it could be a struct, you could use the same struct for image1_result and image1_data
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!