CSE 160 - PowerPoint PPT Presentation

About This Presentation
Title:

CSE 160

Description:

Write a 'launcher' program to specify exactly where programs are to be ... Basic problem: Try to find edges (areas of local sharp contrast) in a greyscale image ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 19
Provided by: philip335
Learn more at: https://cseweb.ucsd.edu
Category:
Tags: cse | greyscale

less

Transcript and Presenter's Notes

Title: CSE 160


1
CSE 160 Lecture 10
  • Programs 1 and 2

2
Program 1
  • Write a launcher program to specify exactly
    where programs are to be spawned, gather output,
    clean up on error
  • Write a ring gather program
  • Write a tree gather program

3
Code Outline for Program 1
  • Code outlines were given in lecture 5
  • We will go over an example implementation for all
    three parts
  • Looking carefully at each PVM function
  • Using XPVM to control a virtual machine
  • Space-time diagrams
  • Trace masks
  • Replaying traces
  • This will interactive

4
Program 2
  • Implement the Sobel (Section 11.5 in WA) edge
    detection algorithm
  • Input/output files in PGM format
  • Master/worker configuration
  • Bag of tasks load balancing
  • Data decomposed by strips
  • Assignment available on the web on Friday

5
Edge Detection
  • Basic problem Try to find edges (areas of local
    sharp contrast) in a greyscale image
  • Think back to basic 1D calculus
  • When df/dx is high, function is changing
    rapidly
  • For 2D problems this is generalized to gradients.
    ?f(x,y) (?f/?x,?f/?y)
  • The goal is to find areas in a picture where the
    ?f(x,y) is high.

6
Approximating the Magnitude of the Gradient
  • ?f(x,y) ?(? f/?x)2 (?f/?y)2
  • For computational simplicity, this is
    approximated as ?f/?x ?f/?y
  • Lets consider the following 3 x 3 matrix of
    values

x0 x1 x2
x3 x4 x5
x6 x7 x8
7
Calculating the Gradient at X4
  • X4 is the pixel of interest. Could try an
    approximation as
  • ? f/?x x5 x3 (difference left and right)
  • ? f/?y x7 x1 (difference top and bottom)
  • One gets much better approximation of all
    surrounding pixels are used to approximate the
    gradient

8
The Sobel Operator
  • Look at calculating ? f/?y
  • ? f/?y x6 x0 2(x7 x1) x9 x3
  • This is only a weighted average of the gradient
    by using neighboring pixels.
  • Extra weight is given to the pixels directly
    above and below the center pixel of interest
  • ? f/?x x2 x0 2(x5 x3) x8 x6

9
Cross Correlation
  • Mask Pixels

x0 x1 x2
x3 x4 x5
x6 x7 x8
w0 w1 w2
w3 w4 w5
w6 w7 w8
?
Cross correlation is ?i?j xiwj Want to
calculate the cross-correlation at each point in
an image using two masks.
10
Final Calculation
  • Calculate a new x4 with the following Sobel
    formula
  • x4 (1/9) (x6 x0 2(x7 x1) x9 x3
  • x2 x0 2(x5 x3) x8 x6))
  • Need to do this at every point in the picture.

11
Master/Worker Model
  • Master reads input/writes final output
  • Give an input file, divide the image into K
    horizontal strips

K Strips
12
Master Spawns P Workers
  • Master will start P (? K) workers
  • The first P strips are sent to the P slaves.
  • Slaves compute the Sobel transform on their
    strip. Return transformed image to the master
  • As the master gets data returned, it doles out
    more strips until the entire image is converted.

13
Bag of tasks Load Balancing
  • For this problem, a task is the Sobel transform
    of an image strip.
  • Workers may compute at different speeds
  • Faster workers get more work to do (Sounds like
    life ?)
  • Slower workers get less work to do
  • For few workers and may tasks, most workers are
    busy all of the time.

14
What to do at the edge of regions to transform?
  • Strip j needs 1 row of pixels from strip j1
    and strip j-1
  • Have master send these 1 pixel rows as part of
    the jth strip.
  • at edges, consider the image to have pixel value
    0 outside the pixel area.

j-1
j
j1
15
Master Pseudo-code
  • Read command line arguments
  • Spawn P worker tasks
  • Read complete image into an array, pad edges with
    zeros (N2)x(M2)
  • Nrowsceil((N2)/K) // rows per block
  • Pkidx0 //row index to pack
  • stripsLeft K
  • for (i 0 i lt P i)
  • label strip i
  • pack label of strip i
  • pack the dimensions of strip i
  • pack the data of strip i
  • send ith strip to ith worker

16
Master Pseudo Code continued
  • stripsleft K P
  • Stripsxformed 0
  • While (stripsleft)
  • receive transformed strip from any worker
  • stripsxformed
  • determine which strip has been sent Save data
  • pack strip S K stripsleft
  • send strip S to this worker
  • stripsleft--

17
Master Continued
  • While (stripsxformed lt K)
  • receive transformed strip from any worker
  • stripsxformed
  • determine strip that was sent save data
  • stripsxformed
  • Broadcast a done message to every worker
  • Write out transformed data

18
Worker Pseudo code
  • done 0
  • While (!done)
  • receive message from parent (pvm_parent())
  • determine message tag (pvm_bufinfo())
  • if (Tag donemessage) break
  • unpack strip id
  • unpack strip dimension
  • unpack strip data
  • transform data
  • pack strip id, dimension
  • pack transformed data
  • send back to parent
Write a Comment
User Comments (0)
About PowerShow.com