Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Ex No:1
AIM:
To write a program to perform text compression algorithm using run length encoding
technique.
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp1,*fp2;
int i=1;
char a,c;
clrscr();
fp1=fopen("a.txt","r");
fp2=fopen("b.txt","w");
a=getc(fp1);
while(!feof(fp1))
{
c=fgetc(fp1);
if(c==a)
{
a=c;
i++;
}
else
{
fprintf(fp2,"%d%c",i,a);
a=c;
i=1;
}
}
printf("successfully compressed");
1
fclose(fp1);
fclose(fp2);
getch();
}
INPUT :
a.txt
______
Aaabbb
OUTPUT:
b.txt
_____
3a3b
Successfully compressed
RESULT:
Thus the above program performed successfully and the output is verified.
Ex no:2
AIM:
To write a program to perform text compression algorithm using packet text method in C
language.
ALGORITHM:
Start the program.
Write some text in the input file
Using the text in input file & compress the content using packet text method.
Write the compressed text (i.e.) translated into another form into output file.
Stop the execution.
PROGRAM:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define RESULTSTRINGMAXLENGTH 255
int packtext(char *text, const bool compress);
int main(void)
{
int original;
char text[]="Quidquid latine dictum sit, altum viditur.";
original=strlen(text);
printf("%s length=%ld\n",text,strlen(text));
packtext(text,true);
printf("compressed length=%ld\nCompression
Ratio=%.0f%%\n",strlen(text),
(float)strlen(text)/original*100);
packtext(text,false);
printf("String Restored: %s length=%ld",text,strlen(text));
return 0;
}
int packtext(char *text, const bool compress)
{
const char dictionary[]=" e as tinthouerhet anreesr d onn or o i y wo tontyo. neisarteed, ctiy
bat snd fal pensestvengitu talehaurllcousa mf dfoof siril hmeg om Icehironsasiossbedepe rli
Tetel nicho lilprcactutThpaeceachh wige ebuaisursulmawaotowtsmploI solyee Cunm rtieno
Sdiwhs.rafincademe.irplk ury Pwoacos gams,duayavucColamowe Aoopu";
int counter,resultcounter=0;
if (strlen(dictionary) != 320)
{
printf("ERROR: Dictionary has the wrong size\n");
return 2;
}
if (compress)
3
{
int dictsearch;
for (counter=0; counter < strlen(text); counter++)
if (text[counter] < 32 || text[counter]==127)
{
printf("ERROR: String contains characters with values out of
range");
return 1;
}
for (counter=0; counter < strlen(text); counter++, resultcounter++)
{
for (dictsearch=0; dictsearch < strlen(dictionary); dictsearch+=2)
if (text[counter]==dictionary[dictsearch] &&
text[counter+1]==dictionary[dictsearch+1])
break;
if (dictsearch < strlen(dictionary)) // we found the characters that we want
{
text[resultcounter]=dictsearch/2+96;
counter++;
}
else
text[resultcounter]=text[counter]-31;
}
text[resultcounter]='\0';
}
else //uncompress
{
char result[RESULTSTRINGMAXLENGTH];
for (counter=0; counter < strlen(text); counter++,resultcounter++)
{
if (text[counter]<96 && text[counter] > 0)
result[resultcounter]=text[counter]+31;
else
{
if (text[counter]>95)
{
result[resultcounter]=dictionary[((int)text[counter]-96)*2];
resultcounter++;
result[resultcounter]=dictionary[((int)text[counter]-96)*2+1];
}
else
{
result[resultcounter]=dictionary[(160+text[counter])*2];
resultcounter++;
result[resultcounter]=dictionary[(160+text[counter])*2+1];
}
}
4
}
result[resultcounter]='\0';
strcpy(text,result);
}
return 0;
}
INPUT :
a.txt
______
Aaaaaabbb
OUTPUT:
b.txt
_____
6a3b
Successfully compressed
RESULT:
Thus the above program performed successfully and the output is verified.
Ex no:3
AIM:
To write a c program to perform image compression algorithm.
ALGORITHM:
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp1,*fp2;
int i=1;
char a,c;
clrscr();
fp1=fopen("rose.jpg","r");
fp2=fopen("bb.jpg","w");
a=fgetc(fp1);
while(!feof(fp1))
{
c=fgetc(fp1);
if(c==a)
{
a=c;
i++;
break;
}
else
{
fprintf(fp2,"%d%c",i,a);
a=c;
i=1;
}
}
printf("\n successfully compressed");
fclose(fp1);
fclose(fp2);
getch();
}
6
INPUT FILE:
rose.jpg
bb.jpg
OUTPUT:
Successfully compressed
RESULT:
Thus the above program performed successfully and the output is verified.
Ex no:4
AIM:
To write a Java program to perform image compression algorithm using Huffman coding.
ALGORITHM:
Start the program.
Open the bmp file in read mode.
Compress the content of the bmp file using Huffman coding technique.
Print the compressed text another file.
Stop the execution.
PROGRAM
File: HuffmanRunner.java
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class HuffmanRunner
{
public static void main(String[] args) throws IOException
{
int numIntensities = 256;
int numPixels = 512*512;
BufferedImage image = ImageIO.read(new File("../lena.bmp"));
int[] histogram = getHistogram(image, numIntensities);
Huffman coder = new Huffman(histogram, numPixels, numIntensities);
String[] codes = coder.getCodes();
int[] codedImage = getCodedImage(codes, image);
FileOutputStream fos = new FileOutputStream(new File("output.dat"));
DataOutputStream dos = new DataOutputStream(fos);
for(int i : codedImage)
{
dos.writeInt(i);
}
dos.close();
fos.close();
}
8
return tempString;
}
private class HuffmanCode
{
private String code;
private int symbol;
public HuffmanCode(String code, int symbol)
{
this.code = code;
this.symbol = symbol;
}
public String getCode()
{
return this.code;
}
public int getSymbol()
{
return this.symbol;
}
}
private class HuffmanComparator implements Comparator<HuffmanNode>
{
@Override
public int compare(HuffmanNode o1, HuffmanNode o2)
{
return new Double(o1.getWeight()).compareTo(new
Double(o2.getWeight()));
}
}
private class HuffmanNode
{
private double weight;
private int symbol;
private HuffmanNode parent;
private HuffmanNode left;
private HuffmanNode right;
private String codePortion;
public HuffmanNode()
{
this.weight = -1.0;
this.symbol = -1;
this.parent = null;
this.left = null;
12
this.right = null;
this.codePortion = "";
}
public double getWeight()
{
return this.weight;
}
public void setWeight(double newWeight)
{
this.weight = newWeight;
}
public int getSymbol()
{
return this.symbol;
}
public void setSymbol(int newSymbol)
{
this.symbol = newSymbol;
}
public HuffmanNode getParent()
{
return this.parent;
}
public void setParent(HuffmanNode newParent)
{
this.parent = newParent;
}
public void setLeft(HuffmanNode newLeft)
{
this.left = newLeft;
}
public void setRight(HuffmanNode newRight)
{
this.right = newRight;
}
public String getCodePortion()
{
return this.codePortion;
}
public void setCodePortion(String newCodePortion)
{
13
this.codePortion = newCodePortion;
}
}
private class HuffmanTree
{
private HuffmanNode root;
public HuffmanTree()
{
root = null;
}
public HuffmanNode getRoot()
{
return this.root;
}
public void setRoot(HuffmanNode newRoot)
{
this.root = newRoot;
}
}
}
INPUT IMAGE:
14
INPUT :
w.jpg
OUTOUT:
bb.jpg
Successfully compressed
RESULT:
Thus the above program performed successfully and the output is verified.
15
Ex no:5
AIM:
To write a Java program to perform image compression algorithm using Lossless and
Lossy Predictive Coding.
ALGORITHM:
Start the program.
Open the bmp file in read mode.
Compress the content of the bmp file using Lossless and Lossy Predictive
Coding.
Print the compressed text another file.
Stop the execution.
PROGRAM
File: Start.java
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.io.IOException;
public class Start {
/**
* @param args
*/
public static void main(String[] args) {
PredictiveLossless p = new PredictiveLossless();
BufferedImage bi=null;
try {
bi = p.getImage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//p.writetToFile(p.getData(bi));
p.writetToFile(p.compressLossy(p.getData(bi)));
System.out.println(292*267/8);
}
}
16
File: PredictiveLossless.java
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class PredictiveLossless {
public int step=2;
public BufferedImage getImage() throws IOException {
BufferedImage bi = ImageIO.read(new File("pikachu.bmp"));
return bi;
}
public byte[] getData(BufferedImage bi) {
DataBuffer db = bi.getRaster().getDataBuffer();
byte[] b = new byte[db.getSize()];
for (int i=0;i < db.getSize();i++) {
b[i]=(byte) db.getElem(i);
}
return b;
}
public void writetToFile(byte[] b) {
System.out.println(b.length);
File f = new File("data.bin");
FileOutputStream fout=null;
try {
fout = new FileOutputStream(f);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
fout.write(b);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public byte[] compress(byte[] b) {
byte[] b2 = new byte[b.length];
for (int i=0;i < b.length;i++) {
if (i==b.length-1) {
b2[i]=b[i];
} else {
17
b2[i]=(byte) (b[i+1]-b[i]);
}
}
return b2;
}
public byte[] compressLossy(byte[] b) {
int current=0;
byte[] b2 = new byte[b.length];
for (int i=0;i < b.length;i++) {
if (i==b.length-1) {
b2[i]=b[i];
} else {
if (b[i]>=current) {
b2[i]=1;
current+=step;
} else {
current-=step;
b2[i]=0;
}
}
}
return b2;
}
}
INPUT FILE:
w.jpg
OUTPUT:
bb.jpg
Successfully compressed
RESULT:
Thus the above program performed successfully and the output is verified.
18
EX NO: 6
AIM:
To develop a filter image using adobe photoshop
ALGORITHM:
Open adobe photoshop 1.0.
Select the file menu -> click open -> browse a picture
Select filter menu from the title bar
Select filter option -> blur -> radial blur
Set the appropriate radial to blur the picture and click ok
19
INPUT:
20
OUTPUT:
21
Ex No:7
AIM
To generate a repeated pattern of image using adobe photoshop
ALGORITHM
Select the file menu and then click open for a sample picture
Select filter menu from the menu bar
Choose pattern maker from the filter menu
New window will be opened and the browsed image will be present
Select a pattern of the picture and click generate
Finally a pattern of image will be displayed.
22
INPUT:
23
OUTPUT:
24
Ex No:8
AIM
To create an animation to represent the growing moon.
PROCEDURE
Select the oval tool in order to draw the moon. u will get a white circle.
Select the oval tool in order to draw the moon. u will get a white circle.
Select the white circle on the worksheet using the selection tool->right click>convert to symbol->select movie clip->give suitable name eg: moon->click ok.
Click on the + symbol again and chose blur-> again adjust the blur x/blur y values.
Place the moon where ever you want on the work area.double click on layer 1 and
rename as MOON.
Select the fill color to black-> select oval tool and draw a circle on the moon to cover
the moon->select the newly added circle-> right click-> convert to symbol-> movie
clip-> name it as Animation.
Go to filter-> select + symbol->give the glow and blur effect as did for moon.
Click on the 149th keyframe of animation layer ->right click->press create motion->
select the animation movie clip and move slowly across the moon.
25
OUTPUT:
26
.
Ex No:9
AIM
To create an animation to indicate a ball Bouncing on steps.
PROCEDURE
Select the line tool and draw the steps. colour it using the paint bucket tool
Select the circle from the tool bar and create a circle on the work area.
Now fill the colour to the circle using the paint bucket tool from the tool bar.
Go to frames right click on the first frame and choose insert key frame.
Slightly move the ball. Repeat the same procedure by adding new key frames to
show the ball change the shape of the ball slightly when it touches the surface.
Go to control and click on test movies .you will observe the ball bouncing on steps.
27
OUTPUT
28
Ex No:10
AIM
To simulate movement of a cloud.
PROCEDURE
In order to create the clouds, go to tool bar and select pencil option, draw the cloud in
layer2.
Fill the colour to the cloud, right click on it- choose convert to symbol option- give the
name as cloud.
Go to frames, insert key frame on both the layer, create the motion tween on 2 nd layer
and move the clouds.
29
OUTPUT
30
:
.
Ex No:11
AIM
Insert another layer-> draw only fan blades and its circle.
Select the fan blades layer and insert new key frame-> select the fan blades by free
transform tool and rotate the circle a little bit.
Repeat the rotation until you get the fan rotation animation
31
OUTPUT:
32
Ex No:12
AIM
To create an animation with the following features.
WELCOME
* Letters should appear one by one
* The fill colour of the text should change to a different colour after
the display of the full word.
PROCEDURE
Choose the textbox from the tool bar. Type the word as WELCOME on layer1.
Select the complete word, increase its Font size and change the colour.
In the timeline window, select the 1st frame-Right click on it-choose insert key frame.
Now delete a last letter {E} and change the colour of the remaining word.
Repeat the above procedure till you delete every word in WELCOME.
Now select all the key frames->Right click ->choose Reverse key frames.
After reversing the frames copy the last frame and paste on its next. now in the new
frame
Select all the complete word welcome and change the colour.
33
Finally, go to control-click on test movie you will get the required animation.
OUTPUT:
34
Ex No:13
AIM
To simulate a ball hitting another ball.
PROCEDURE
Choose the circle option displayed in the toolbar. create two circle at the opposite ends.
Go to frames-> right click on the 1st blank frame and click insert key frames.
Select the 1st ball and make it to move towards the other till it touches.
Change the shape of the ball using free transform tool as soon as the two ball touches
Each other. after hitting each other make them to move towards opposite direction.
Before moving to the opposite direction bring back the balls to its original shapes.
35
OUTPUT:
36
.
Ex No:14
AIM
To create an animated cursor using startdrag("ss",True); mouse.hide();
PROCEDURE
Insert or draw any object of your choice for example butterfly in this example.
Using free transform tool select the object-right click-convert to symbol- select movie
Clip- give the name(mm)- click ok.
Enter the instance name as (mm) using the property tool box.(same as the movie clip
Name).
Select the first key frame in the action layer- go to windows- click action.
You will get action frame- enter the following code in the action frame.
Mouse.hide();
This.mm.onenterframe=function() {
Startdrag(this,true);
};
OUTPUT:
38
Ex No:15
IMAGE EDITING
AIM
To extract the flower only from given Photographic image and organize it on a
background. Selecting your own background for organisation.
PROCEDURE
Open adobe Photoshop 7.0-> file->open-> choose a file and open it.
Select the flower from the image using the lasso tool.
Choose appropriate background and foreground colour from the tool bar.
Go to edit->paste.
39
OUTPUT:
40
41
42
Ex No:16
AIM
To adjust the brightness and contrast of the picture so that it gives an elegant look.
PROCEDURE
Open adobe Photoshop 7.0-> file->open-> choose a file and open it.
Go to image->adjustments->Brightness/Contrast.
After getting the Brightness/Contrast window adjust the brightness and contrast by
Dragging the appropriate bar setting.
43
OUTPUT:
44
Ex No:17
AIM
To remove the arrows and text from the given photographic image.
PROCEDURE
Open adobe Photoshop 7.0-> file->open-> choose a file with arrows and some
text -> open it.
Select the arrows from lasso tool from the tool bar which you want to delete->go
to edit-> cut.
Select the text on the image using text tool and press delete.
45
OUTPUT:
Original image
46
Ex No:18
AIM
To use appropriate tool(s) from the toolbox, cut The objects from 3 files (f1.jpg, f2.jpg &
f3.jpg); organise them in a single file and apply feather effects.
PROCEDURE
Select the flower in it using lasso tool ->right click->feather-> give feather radius 20
pixels.
Go to edit-> copy-> open a new file with height 500 and width also 500->paste the
flower.
Repeat the same procedure for f2.jpg and f3.jpg-> select the flower ->give feather effect>edit->copy-> open a new file-> paste.
You will get o final single file with 3 flowers from different files.
47
OUTPUT
F1.JPG
F2.JPG
F3.JPG
FINAL IMAGE
48
Ex No:19
AIM
To display the background given (filename:garden.jpg) through your name using mask.
PROCEDURE
Click open.
The selected image will be stored in your library. Open library and drag the image on the
Go to view->zoom out->resize the picture such that it should fit the work area.
Insert layer2. choose the text tool from the toolbar and type your name.
Select the text to change its font size and colour of your choice. place the text on the left
of the workarea.
Right click on the 70th keyframe of layer 2 and insert a keyframe. move the text to the
right side of the workarea->right click on the 69th frame of layer 2-> choose create
motion tween.
49
OUTPUT:
50
Ex No:20
AIM
To make anyone of one of the parrots black & White in a given picture.
PROCEDURE
51
OUTPUT
Original picture
Modified picture
52
Ex No:21
AIM
To change a circle into a squre using flash.
PROCEDURE
Go to start->macromedia->flash document
Select the circle tool from the tool bar. draw a circle on the work area.colour it
Click on the 40th key frame-> insert new key frame.
Selecting the last key frame->draw a rectangle on the circle by selecting the rectangle
tool bar so that it will cover the circle. colour the rectangle by the different colour.
Again click on the last frame->under properties->under tween->change the option
shape from none.
Then again select the last but one frame->go to properties->tween->change to shape.
Go to control->test movie->see the circle changing in to rectangle.
53
OUTPUT
54