Question: with the given julia code: abstract type AbstractStencil end struct AverageStencil < : AbstractStencil end apply _ to _ 3 x 3 ( s::AverageStencil, A

with the given julia code:
abstract type AbstractStencil end
struct AverageStencil <: AbstractStencil end
apply_to_3x3(s::AverageStencil, A33)= sum(A33)/ length(A33)
function stencil_demo(s::AbstractStencil)
count =0
plot_next(A)= subplot(1,4,count+=1), imshow(A[:,:,[1,1,1]])
for noise =[0,0.3]
A = test_image(1,50, noise)
plot_next(A)
plot_next(apply_stencil(s,A))
end
end
function apply_stencil(s::AbstractStencil, A)
# Your code
B =0*A
for i =2:size(A,1)-1, j =2:size(A,2)-1
B[i,j]= apply_to_3x3(s,A)
end
return B
end
In Julia code: define a new subtype EdgeStencil which applies the same operation as maxabsgradfilter in the lecture notes.
here is the function from the lecture notes
function image_maxabsgradfilter(A)
B =0*A
for i =2:size(A,1)-1, j =2:size(A,2)-1
a = A[i-1:i+1, j-1:j+1]
B[i,j]= max(abs(a[3,2]- a[1,2]), abs(a[2,3]- a[2,1]))
end
return B
end
then test with
stencil_demo(EdgeStencil())

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!