Author Topic: PHP script to remove black frames from from silent shutter pics  (Read 3905 times)

pimnl

  • New to the forum
  • *
  • Posts: 3
When I turn on silent picture mode on my 550d, and activate the intervalometer.. Some pictures have purple distortions, and others are black.
By turning off Global_draw the purple distortion problem is fixed. However, I keep getting the black frames.

I'm not sure if there is a solution for the black frames? So I created one myself.

The following PHP script:
- finds all black jpg's
- finds for each black jpg the image that comes after in the sequence, and the one before
- merges these two images to a new image, where they are blended 50%/50% on top of eachother
- overwrites the black frame with the blended image



Code: [Select]
<?php
error_reporting
(E_ALL E_NOTICE);
?>


When taking silent pictures with magic lantern, often black frames occur, or frames with purple distortion in it.
It seems to fix the purple distortion, the easiest thing to do is to turn of Global draw.
<br><Br>
I haven't found a fix to get rid of the black frames. Therefore this script finds black frames, and merges the picture before and after the black frame to a new picture, to replace the black frame.<br>
Make sure the folder with the images are writeable(not read-only)!
<Br><br><Br>

In what folder are the .jpg photos?<Br>
<form>
Folder path: <input name="folder" value="<?php
if($_GET['folder']){ echo $_GET['folder'];} else { echo 'D:\550d\cusco';}
?>
"><Br>
Black frames are smaller than: <input name="filesize" value="<?php
if($_GET['filesize']){ echo $_GET['filesize'];} else { echo '100';}
?>
" size=3>KB<Br>
<input type="hidden" name="submit" value="1">
<input type="checkbox" name="replace" value="1"> Replace black frames with merged before and after picture<br>
<input type="submit" name="scan" value="scan folder for black frames"><Br>
</form>

<?php

function replace_picture($path,$image){

// echo '<li>so you want to replace?';
// echo '<li>path: '.$path;
// echo '<li>image: '.$image;
// get the last number in the image:
preg_match('/^(.+?)([0-9]+)(\..+?)$/',$image,$m);
// echo '<li>number: '.$m[2];
$number_before $m[2]-1;
$number_after $m[2]+1;
// echo '<li>number_before: '.$m[1].$number_before.$m[3];
// echo '<li>number_after: '.$m[1].$number_after.$m[3];

// Create image instances
$dest imagecreatefromjpeg($path.'\\'.$m[1].$number_before.$m[3]);
$src imagecreatefromjpeg($path.'\\'.$m[1].$number_after.$m[3]);

// Copy and merge
imagecopymerge($dest$src00004000200050);

if (is_writable($path.'\\'.$image)) {
    echo '';
} else {
    echo '<li><font color=red>Error, can\'t write the file. Make sure the folder is not read-only. Right mouse button on folder -> attributes -> uncheck read-only</font>';
}
imagejpeg($dest$path.'\\'.$image80);

echo '<li>Image <u>'.$image.'</u> has been replaced with a merged version of image <u>'.$m[1].$number_before.$m[3].'</u> and <u>'.$m[1].$number_after.$m[3].'</u>';
imagedestroy($dest);
imagedestroy($src);


}

if(
$_GET['submit']){

// does folder exist?
if (file_exists($_GET['folder'])) {
    echo "The folder ".$_GET['folder']." exists";

// get all the files
if ($handle opendir($_GET['folder'])) {
    while (false !== ($entry readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            
            // is it a jpg file?
            if(strpos($entry,'.jpg') OR strpos($entry,'.JPG')){
$size filesize($_GET['folder'].'\\'.$entry);
$size round($size/1000);

if($size $_GET['filesize']){
$small_files_detected 1;
if(!$detected_black_frames){
echo '<br><br><b>The following images are smaller than '.$_GET['filesize'].'kb. And the first pixel of the image is BLACK</b><br><br>';
$detected_black_frames 1;
}

$im imagecreatefromjpeg($_GET['folder'].'\\'.$entry);
$rgb imagecolorat($im11);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b $rgb 0xFF;

if($r+$g+$b == 0){
             echo '<li><a href="'.$_GET['folder'].'\\'.$entry.'">'.$_GET['folder'].'\\'.$entry.'</a> '.$size.'kb';
}
if($_GET['replace']){
replace_picture($_GET['folder'],$entry);
}
}

            }
            
        }
    }
    closedir($handle);
    if(!$small_files_detected){
     echo '<br><Br><font color=red>No files smaller than '.$_GET['filesize'].' where detected</font>';
    }
}
    
} else {
    echo "The folder ".$_GET['folder']." does not exist(?) Or this script can't access it:(";
}

}

A better solution would be not to get any black frames at all. Though I don't know how. Tips welcome!