⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmp3.java

📁 It is basic in which i am compressing bitmap images.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				dminouter=200000.0;
				indexouter1=k;
				//for(k=0;k<limit;k++)
				//{
					//k=0;
					indexouter1=k;

				//find first not visited 0 cannot be visited
				for(i=0;i<limit;i++)
					if(visited[i]==false && i!=k)
						break;
				//calculate difference between 0 and i
				indexouter2=i;
				d=0;
				for(j=0;j<blocksize;j++)
					d+=xg[indexouter1][j]-xg[indexouter2][j];
				//if(d<dminouter)
					dminouter=d;
				//search for smaller distance with other not visited
				for(i=indexouter2+1;i<limit;i++)
				{
					if(visited[i]==false)
					{
						d=0;
						for(j=0;j<blocksize;j++)
						{
								d+=xg[indexouter1][j]-xg[i][j];
						}

						if(d < dminouter)
						{
							dminouter=d;
							indexouter2=i;
						}
					}
					//douter=
				}
				if(dminouter<dall)
				{
					dall=dminouter;
					indexall1=k;
					indexall2=indexouter2;
				}
			}//end of for loop of k
			indexouter1=indexall1;//modified to all comparisons
			indexouter2=indexall2;
				visited[indexouter2]=true;
				for(j=0;j<blocksize;j++)
				{
					xg[indexouter1][j]=(xg[indexouter1][j]+xg[indexouter2][j])/2;
				}
				counter=0;
				for(i=0;i<limit;i++)
				{
					if(visited[i]==false)
					{
						counter++;
					}
				}//end of counting loops
				p("\nRemaining blocks for GREEN: "+counter);
				if(counter<=N)
				{
					complete=true;
				}
			}//end of while complete loop
			p("\nCopying paired codewords for GREEN..");
			rcnt=0;
			for(i=0;i<limit;i++)
			{
				if(visited[i]==false)
				{
					for(j=0;j<blocksize;j++)
					{
						//c[rcnt][j]=x[i][j];
						cg[rcnt][j]=xg[i][j];
						//cb[rcnt][j]=xb[i][j];
					}
					rcnt++;
				}
			}

			//For BLUE pixels
			complete=false;
			for(i=0;i<limit;i++)
			{
				visited[i]=false;
			}
			while(complete==false)
			{
				dall=200000.0;
				indexall1=0;
				indexall2=1;
				for(k=0;k<limit;k++)
				{
				dminouter=200000.0;
				indexouter1=k;
				//for(k=0;k<limit;k++)
				//{
					//k=0;
					indexouter1=k;

				//find first not visited 0 cannot be visited
				for(i=0;i<limit;i++)
					if(visited[i]==false && i!=k)
						break;
				//calculate difference between 0 and i
				indexouter2=i;
				d=0;
				for(j=0;j<blocksize;j++)
					d+=xb[indexouter1][j]-xb[indexouter2][j];
				//if(d<dminouter)
					dminouter=d;
				//search for smaller distance with other not visited
				for(i=indexouter2+1;i<limit;i++)
				{
					if(visited[i]==false)
					{
						d=0;
						for(j=0;j<blocksize;j++)
						{
								d+=xb[indexouter1][j]-xb[i][j];
						}

						if(d < dminouter)
						{
							dminouter=d;
							indexouter2=i;
						}
					}
					//douter=
				}
				if(dminouter<dall)
				{
					dall=dminouter;
					indexall1=k;
					indexall2=indexouter2;
				}
			}//end of for loop of k
			indexouter1=indexall1;//modified to all comparisons
			indexouter2=indexall2;
				visited[indexouter2]=true;
				for(j=0;j<blocksize;j++)
				{
					xb[indexouter1][j]=(xb[indexouter1][j]+xb[indexouter2][j])/2;
				}
				counter=0;
				for(i=0;i<limit;i++)
				{
					if(visited[i]==false)
					{
						counter++;
					}
				}//end of counting loops
				p("\nRemaining blocks for BLUE: "+counter);
				if(counter<=N)
				{
					complete=true;
				}
			}//end of while complete loop
			p("\nCopying paired codewords for BLUE..");
			rcnt=0;
			for(i=0;i<limit;i++)
			{
				if(visited[i]==false)
				{
					for(j=0;j<blocksize;j++)
					{
						//c[rcnt][j]=x[i][j];
						//cg[rcnt][j]=xg[i][j];
						cb[rcnt][j]=xb[i][j];
					}
					rcnt++;
				}
			}


	//*/
	/*Completed for all three colors*/
	p ("\nReading image...");
	fin = new FileInputStream (fnames);
	rdimg (fin);
	fin.close ();

	write_code ();
	read_code ();
	match_save ();
	error_img ();
	//write_map();
	p ("\nAlgorithm Completed Successfully");
    }


    void encode () throws Exception
    {
	p ("\nEncoding a file");
	InputStream fin = new FileInputStream (fnames);
	rdimg (fin);
	fin.close ();
	calcu ();
	read_code ();
	match_save ();
	error_img ();
	p ("\nEncoding Complete...");

    }


    void decode () throws Exception
    {
	p ("\nDecoding a file");
	width = Integer.parseInt (wt.getText ());
	height = width;
	ppixel = Integer.parseInt (cmp.getText ());
	calcu ();
	read_code ();
	read_map_save ();
	p ("\nDecoding Complete...");
    }



    public void actionPerformed (ActionEvent ae)
    {
	if (ae.getSource () == b1)
	{
	    try
	    {
		open ();
	    }
	    catch (Exception ie)
	    {
	    }
	}
	if (ae.getSource () == b2)
	{
	    try
	    {
		save ();
	    }
	    catch (IOException ie)
	    {
	    }
	}
	if (ae.getSource () == bb1)
	{
	    try
	    {
		res_timer ();
		lbg ();
		print_time ();
	    }
	    catch (Exception ie)
	    {
	    }
	}
	if (ae.getSource () == bb2)
	{
	    try
	    {
		res_timer ();
		mlbg ();
		print_time ();
	    }
	    catch (Exception ie)
	    {
	    }
	}
	if (ae.getSource () == bb3)
	{
	    try
	    {
		res_timer ();
		kmean ();
		print_time ();
	    }
	    catch (Exception ie)
	    {
	    }
	}
	if (ae.getSource () == bb4)
	{
	    try
	    {
		res_timer ();
		pnn ();
		print_time ();
	    }
	    catch (Exception ie)
	    {
	    }
	}
	if (ae.getSource () == bm1)
	{
	    try
	    {
		res_timer ();
		encode ();
		print_time ();
	    }
	    catch (Exception ie)
	    {
	    }
	}
	if (ae.getSource () == bm2)
	{
	    try
	    {
		res_timer ();
		decode ();
		print_time ();
	    }
	    catch (Exception ie)
	    {
	    }
	}
	if (ae.getSource () == b3)
	{
	    try
	    {
		window.setVisible (true);
	    }
	    catch (Exception ie)
	    {
	    }
	}

    }


    public static void main (String args[]) throws IOException
    {
	bmp3 mm1;
	mm1 = new bmp3 ();
	mm1.setSize (535, 600);
	mm1.setLocation (50, 40);
	mm1.setVisible (true);
    }
}

class frame extends Frame
{
    JLabel l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, l17, l18, l19, l20;

    frame (bmp3 af)
    {
	super ("Help");
	setLayout (new FlowLayout ());
	addWindowListener (new WindowAdapter ()
	{
	    public void
		windowClosing (WindowEvent e)
	    {
		e.getSource ();
		setVisible (false);
	    }
	}
	);

	l1 = new JLabel ("The steps for the use of application are as given below:                                                     ");
	l2 = new JLabel ("1.The compilation and running of the application using JAVA compiler is the basic step in this application.                                                                                                                            ");
	l3 = new JLabel ("2.The interface is seen on running the application.Now the necessary fields are to be filled appropriately to obtain the compression and decompression of the bitmap images.");
	l4 = new JLabel ("3.Steps for compression:3.1 Enter the Input Image to be compressed in INPUT FILENAME Block by browsing through the files.                                                                                       ");
	l5 = new JLabel ("3.2Enter the name of the Output Image so that the output image is stored with the name entered,browsing through directories for saving is a better option.                                      ");
	l6 = new JLabel ("3.3 Enter the Width And Height of the Bitmap Image.Note: The Image should have same width  and height i.e.it should be a square image with dimensions <= 256*2563.           ");
	l7 = new JLabel ("3.4 Enter the Values between 1 and 4 for grouping of the pixels for vector quantization.Value 1 gives minimum compression and minimum error while the Value 4 gives              ");
	l12 = new JLabel ("maximum compression and more error.So depending on the choice of compression enter the value.                                                                                                                       ");
	l8 = new JLabel ("3.5If the compression is being done for the first time then PLEASE click on the Algorithm to be used for Encoding i.e. K-Mean Or PNN.                                                                           ");
	l9 = new JLabel ("3.6On clicking the Codebook is formed and the image is encoded according to the algorithm selected.                                                                                                                                   ");
	l10 = new JLabel ("3.7PNN requires much more time for encoding then K-Mean since it has many iterations so it is recommended to use PNN only if ENCODING is not urgent or else use K-Mean.");
	l11 = new JLabel ("3.8For subsequent encoding just click on ENCODE for encoding and the last formed codebook is used for encoding.                                                                                                          ");
	l19 = new JLabel ("                                                  *Steps for Decompression*                                            ");
	l13 = new JLabel ("1.Enter the filename of the image to be decompressed in INPUT FILENAME box and browsing should be used for the same.                                                                                           ");
	l14 = new JLabel ("2.Enter the filename of the image to be saved after decompression in OUTPUT FILENAME                                                                                                                                                         ");
	l15 = new JLabel ("3.Enter the width and height and also the grouping of pixel in respective boxes.                                                                                                                                                                              ");
	l16 = new JLabel ("4.Click on DECODE for decoding of image. The decoded image is displayed.                                                                                                                                                                                 ");
	l17 = new JLabel ("5.The Error Image is generated after encoding of the image it is the Quantization Error introduced in the image.                                                                                                                    ");
	l20 = new JLabel ("The error image is generated to give theintimation of the amountof error that will be introducedin the image after                                                                                                           ");
	l18 = new JLabel ("Vector Quantization. So depending on the use of image the compression is to be used since this is LOSSY COMPRESSION technique.                                                                 ");

	add (l1);
	add (l2);
	add (l3);
	add (l4);
	add (l5);
	add (l6);
	add (l7);
	add (l12);
	add (l8);
	add (l9);
	add (l10);
	add (l11);
	add (l19);
	add (l13);
	add (l14);
	add (l15);
	add (l16);
	add (l17);
	add (l20);
	add (l18);

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -