Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A sliding window operator replaces each pixel with some function of its 8 neighb

ID: 3687472 • Letter: A

Question

A sliding window operator replaces each pixel with some function of its 8 neighbors (and itself). Consider the following 3X3 window:

a b c

d e f

g h i Then, pixel e would be replaced by some function f(a,b,c,d,e,f,g,h,i). One way to detect edges is to use the function 5e-(b+d+f+h). Note that this is a sliding window operator unlike the non-overlapping windows in the previous task - that is, the window is always a window around the pixel whose value is being computed.

Write an edge detector function, named edgeDet. For pixels at the left/right/top/bottom edges of the image, consider their neighbors to be 'wrapped around' to the other end. For example row 0 would be considered to be the row after the last row of the image.

Explanation / Answer

import java.net.*;

import java.io.*;

import java.rmi.*;

public class slidsender

{

public static void main(String a[])throws Exception

{

ServerSocket ser=new ServerSocket(10);

Socket s=ser.accept();

DataInputStream in=new DataInputStream(System.in);

DataInputStream in1=new DataInputStream(s.getInputStream());

String sbuff[]=new String[8];

PrintStream p;

int sptr=0,sws=8,nf,ano,i;

String ch;

do

{

p=new PrintStream(s.getOutputStream());

System.out.print("Enter the no. of frames : ");

nf=Integer.parseInt(in.readLine());

p.println(nf);

if(nf<=sws-1)

{

System.out.println("Enter "+nf+" Messages to be send ");

for(i=1;i<=nf;i++)

{

sbuff[sptr]=in.readLine();

p.println(sbuff[sptr]);

sptr=++sptr%8;

}

sws-=nf;

System.out.print("Acknowledgment received");

ano=Integer.parseInt(in1.readLine());

System.out.println(" for "+ano+" frames");

sws+=nf;

}

else

{

System.out.println("The no. of frames exceeds window size");

break;

}

System.out.print(" Do you wants to send some more frames : ");

ch=in.readLine(); p.println(ch);

}

while(ch.equals("yes"));

s.close();

}

}

//RECEIVER PROGRAM

import java.net.*;

import java.io.*;

class slidreceiver

{

public static void main(String a[])throws Exception

{

Socket s=new Socket(InetAddress.getLocalHost(),10);

DataInputStream in=new DataInputStream(s.getInputStream());

PrintStream p=new PrintStream(s.getOutputStream());

int i=0,rptr=-1,nf,rws=8;

String rbuf[]=new String[8];

String ch; System.out.println();

do

{

nf=Integer.parseInt(in.readLine());

if(nf<=rws-1)

{

for(i=1;i<=nf;i++)

{

rptr=++rptr%8;

rbuf[rptr]=in.readLine();

System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]);

}

rws-=nf;

System.out.println(" Acknowledgment sent ");

p.println(rptr+1); rws+=nf; }

else

break;

ch=in.readLine();

}

while(ch.equals("yes"));

}

}

OUTPUT:

//SENDER OUTPUT

Enter the no. of frames : 4

Enter 4 Messages to be send

hiii

how r u

i am fine

how is evryone

Acknowledgment received for 4 frames

Do you wants to send some more frames : no

//RECEIVER OUTPUT

The received Frame 0 is : hiii

The received Frame 1 is : how r u

The received Frame 2 is : i am fine

The received Frame 3 is : how is evryone

Acknowledgment sent

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote