Multiple GPU to run one filter on multiple images

조회 수: 2 (최근 30일)
Muhammad Abir
Muhammad Abir 2020년 11월 16일
편집: Muhammad Abir 2020년 11월 17일
Hello,
I have 100 2048 x 2048 images that I want to run apply median filter on them. The process is very slow if I use 5 x 5 or 7 x 7 filter. I have 4 GPUs, so I want write a Matlab code that can apply median filter to all 100 images and use all 4 GPUs. I was trying to use parfoor but didn't get to make it run. Can someone please help me on that?
Thanks in advance

답변 (1개)

Muhammad Abir
Muhammad Abir 2020년 11월 17일
편집: Muhammad Abir 2020년 11월 17일
Here is my code. I found that the process is slower using GPU than CPU
clc
clear all
close all
ImageFolder = uigetdir('D:\', 'Select Image Directory');
[parentFolder, thisFolder] = fileparts(ImageFolder);
fileListing = dir(parentFolder);
fileListing(ismember( {fileListing.name}, {'.', '..'})) = [];
areAFolder = [fileListing.isdir];
folderListing = fileListing(areAFolder);
RawImage = [dir([ImageFolder '/*.tif']);dir([ImageFolder '/*.tiff']);...
dir([ImageFolder '/*.png']); dir([ImageFolder '/*.jpg']);...
dir([ImageFolder '/*.dcm']); dir([ImageFolder '/*.fits']);...
dir([ImageFolder '/*.fts']); dir([ImageFolder '/*.img']);...
dir([ImageFolder '/*.raw']); dir([ImageFolder '/*.his']);...
dir([ImageFolder '/*.hdr']); dir([ImageFolder '/*.nitf'])];
RawFileNames= {RawImage(:,1).name}';
RawFilenames = fullfile(ImageFolder, RawFileNames);
RawImageData = cellfun(@ReadInputImage, RawFilenames , 'uniformoutput', 0);
for k = 1 : length(folderListing)
thisFolder = fullfile(folderListing(k).folder, folderListing(k).name);
[~, theFolder] = fileparts(thisFolder);
if matches(theFolder, ["Bright","bright","gain","Gain"])
BrightImage= [dir([thisFolder '/*.tif']);dir([thisFolder '/*.tiff']);...
dir([thisFolder '/*.png']); dir([thisFolder '/*.jpg']);...
dir([thisFolder '/*.dcm']); dir([thisFolder '/*.fits']);...
dir([thisFolder '/*.fts']); dir([thisFolder '/*.img']);...
dir([thisFolder '/*.raw']); dir([thisFolder '/*.his']);...
dir([thisFolder '/*.hdr']); dir([thisFolder '/*.nitf'])];
BrightFileNames= {BrightImage(:,1).name}';
BrightFilenames = fullfile(thisFolder, BrightFileNames);
BrightImageData = cellfun(@ReadInputImage, BrightFilenames , 'uniformoutput', 0);
elseif matches(theFolder, {'Dark', 'dark', 'Offset', 'offset'})
DarkImage= [dir([thisFolder '/*.tif']);dir([thisFolder '/*.tiff']);...
dir([thisFolder '/*.png']); dir([thisFolder '/*.jpg']);...
dir([thisFolder '/*.dcm']); dir([thisFolder '/*.fits']);...
dir([thisFolder '/*.fts']); dir([thisFolder '/*.img']);...
dir([thisFolder '/*.raw']); dir([thisFolder '/*.his']);...
dir([thisFolder '/*.hdr']); dir([thisFolder '/*.nitf'])];
DarkFileNames= {DarkImage(:,1).name}';
DarkFilenames = fullfile(thisFolder, DarkFileNames);
DarkImageData = cellfun(@ReadInputImage, DarkFilenames , 'uniformoutput', 0);
end
end
if ~exist('BrightImageData','var') || isempty(BrightImageData) || ~exist ('DarkImageData','var') || isempty(DarkImageData)
msgbox(sprintf('Either Bright or Dark Images Not Found','warn'));
end
tic;
parpool('local',gpuDeviceCount);
parfor ii = 1:numel(RawImageData)
G = gpuArray(RawImageData{ii});
FilterImage{ii}=medfilt2(G,[5,5]);
end
delete(gcp('nocreate'));
toc;

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by