mathematical operation on each element of gpuArray

How can i do mathematical operation on each element of gpuArray with the equation below? s = 2r(i, j) − r(i, j +1) + r(i, j −1). here r is the image matrix. I've written the code below:
im = imread('(HTC-1-M7)1.jpg');
tic
img = gpuArray(im);
for j =2: size(im,2) -1
A(:,:,:) = 2*img(:, :,:) -img(:,j+1,:) + img(:, j-1,:);
end
B = gather(A);
toc
Is there anyway to apply equation on each element of gpuarray with function like arrayfun without using loop? Thanks in advance.

2 件のコメント

Matt J
Matt J 2018 年 1 月 22 日
Are you certain that it is not a 2nd order differencing filter that you want:
s = 2r(i, j) r(i, j +1) - r(i, j 1)
Rouhan Noor
Rouhan Noor 2018 年 1 月 22 日
編集済み: Rouhan Noor 2018 年 1 月 22 日
actually I found it from a research paper from IEEE. They derive this equation for row wise(x-axis) second order differentiation. But i have come to know about imgradientxy function, not sure this function does the same stuff like this equation or not.

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2018 年 1 月 22 日
編集済み: Matt J 2018 年 1 月 22 日

0 投票

B=gather( imfilter(gpuArray(img), [+1,2,-1]) );

4 件のコメント

Rouhan Noor
Rouhan Noor 2018 年 1 月 22 日
actually I found it on a research paper from IEEE. They derive this equation for row wise(x-axis) second order differentiation. But i have come to know about imgradientxy function, not sure this function does the same stuff like this equation or not.
Rouhan Noor
Rouhan Noor 2018 年 1 月 22 日
if you don't mind could you explain the code how does it works? I'm newbie in matlab.
Rouhan Noor
Rouhan Noor 2018 年 1 月 22 日
Is there any builin function in matlab to determine the second order derivative of image like the equation above?
Matt J
Matt J 2018 年 1 月 22 日
編集済み: Matt J 2018 年 1 月 22 日
B=gather( diff(gpuArray(img),2,2) );

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2018 年 1 月 22 日

編集済み:

2018 年 1 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by