Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>title</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="description" content="" />
- <meta name="keywords" content="" />
- <meta name="robots" content="index,follow" />
- <!-- <link rel="stylesheet" type="text/css" href="styles.css" /> -->
- <script language="javascript" type="text/javascript" src="flot/jquery.js"></script>
- <script language="javascript" type="text/javascript" src="flot/jquery.flot.js"></script>
- <style type="text/css">
- body {
- /*background: url('pattern.png');*/
- }
- #rs {
- color: #ff0000;
- }
- #gs {
- color: #00ff00;
- }
- #bs {
- color: #0000ff;
- }
- #flot {
- width: 1024px;
- height: 768px;
- }
- </style>
- <script type="text/javascript">
- window.onload = function() {
- <?php
- main();
- if (count($rs)>1) {
- $ra = autocorel($rs);
- $ga = autocorel($gs);
- $ba = autocorel($bs);
- }
- echo flot_data_string('d1',$ra) . "\n";
- echo flot_data_string('d2',$ga) . "\n";
- echo flot_data_string('d3',$ba) . "\n";
- ?>
- $.plot("#flot", [ d1, d2, d3 ]);
- };
- </script>
- </head>
- <?php
- function echo_post_var($var,$def) {
- if (isset($_POST[$var]))
- echo $_POST[$var];
- else
- echo $def;
- }
- ?>
- <body>
- <form method="post" action="index.php" enctype="application/x-www-form-urlencoded">
- x1<input type="text" name="x1" value="<?php echo_post_var('x1',0); ?>" size="3"/>
- y2<input type="text" name="y1" value="<?php echo_post_var('y1',0); ?>" size="3"/>
- x2<input type="text" name="x2" value="<?php echo_post_var('x2',100); ?>" size="3"/>
- y2<input type="text" name="y2" value="<?php echo_post_var('y2',0); ?>" size="3"/>
- <input type="submit" value="go" />
- </form>
- <div id="flot"></div>
- <?php
- $rs = array();
- $gs = array();
- $bs = array();
- function main() {
- global $rs,$gs,$bs;
- $coords = array('x1','x2','y1','y2');
- $coords_are_set = TRUE;
- foreach ($coords as $coord) {
- if (!isset($_POST[$coord])) {
- $coords_are_set = FALSE;
- echo "coord $coord are not set<br>";
- } else {
- $$coord = $_POST[$coord];
- }
- }
- if ($coords_are_set == FALSE) {
- //exit("some coords are not set");
- return;
- }
- $image = imagecreatefromjpeg("image.jpg");
- $xl = $x2 - $x1;
- $yl = $y2 - $y1;
- if ($xl == 0 || $yl == 0) {
- $xk = 0;
- $yk = 0;
- if ( $xl == 0 ) {
- $l = $yl;
- $yk = 1;
- } else {
- $l = $xl;
- $xk = 1;
- }
- for ($i=0;$i<$l;$i++) {
- $rgb = imagecolorat($image, $x1+$xk*$i, $y1+$yk*$i);
- $r = ($rgb >> 16) & 0xFF;
- $g = ($rgb >> 8) & 0xFF;
- $b = $rgb & 0xFF;
- $rs[] = $r;
- $gs[] = $g;
- $bs[] = $b;
- }
- }
- }
- function array_to_string($ar) {
- $s = '';
- foreach($ar as $v) {
- $s = $s . $v . ' ';
- }
- return $s;
- }
- function flot_data_string($name,$ar) {
- $s = "var $name = [";
- $l = count($ar);
- for ($i=0;$i<$l-1;$i++) {
- $x = $i+1;
- $y = $ar[$i];
- $s = $s . "[$x,$y],";
- }
- $x = $l;
- $y = $ar[$l-1];
- $s = $s . "[$x,$y]];";
- return $s;
- }
- function autocorel($ar) {
- $l = count($ar);
- $sum = array_sum($ar);
- $avg = $sum / $l;
- $disp = 0;
- $ar_norm = array();
- foreach ($ar as $v) {
- $disp = $disp + pow($v - $avg,2.0);
- }
- $disp = $disp / $l;
- $sko = sqrt($disp);
- foreach ($ar as $v) {
- $ar_norm[] = ($v - $avg) / $sko;
- }
- //echo "sko: $sko; avg: $avg";
- //return array_to_string($ar_norm);
- $ar_corel = array();
- $corel = 0;
- for ($i=1;$i<$l*2/3;$i++) {
- for ($j=0;$j<$l-$i;$j++) {
- $corel = $corel + $ar_norm[$j]*$ar_norm[$j+$i];
- }
- $corel = $corel;
- $ar_corel[] = $corel;
- }
- return $ar_corel; //flot_data_string('blah',$ar_corel); //array_to_string($ar_corel);
- }
- //$rs_text = array_to_string($rs);
- //$gs_text = array_to_string($gs);
- //$bs_text = array_to_string($bs);
- //echo '<div id="rs">' . $rs_text . '</div><div id="gs">' . $gs_text . '</div><div id="bs">' . $bs_text . '</div>';
- //echo $ac;
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement