CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Help me code this logic please


New User

Jan 1, 2014, 8:37 PM

Post #1 of 5 (18628 views)
Help me code this logic please Can't Post

Please help, I know it can be done.

I have 60,075 .txt files(TAB delimited) that are created from ImageJ that contains the XY coordinates and RGB tuples for each frame(60075 frames) of a video. (Macro took me days to make, 16 hours to run, and ate up 360GB)

I need the RGB tuple information from one coordinate x=384, y=377 for each frame. (this information is not always found on the same line#, which is why I need a piece of logic to find the data)

I need this data in a new file that can be loaded into a spreadsheet. So it needs to have either TAB or comma separated values. The file being created will have 60076 lines of data when completed.

Each RGB tuple file is named 00000.txt - 60075.txt
(G:\Frames as bitmap\00000.txt) <-where it sits for me

RGB tuple file example line;
0 (TAB) 0 (TAB) 113 (TAB) 0 (TAB) 255 {X Y R G B}

Desired new file example line
00000,255,255,255 or 00000 (TAB) 255 (TAB) 255 (TAB) 255

I would like to be able to adapt this based on changes to directory and coordinates desired.

Thank you for your time in advance. My end goal is to prove the police edited an arrest video. Still have to do statistical analysis after this to prove pixel skew.

New User

Jan 1, 2014, 9:08 PM

Post #2 of 5 (18626 views)
Re: [AwsedreswA] Help me code this logic please [In reply to] Can't Post

After looking at this again, I am thinking this may end up not being very elegant (like the macro I used in ImageJ). There may be the need to call on each file to open and run the logic on.

I have a list of numbers to 60075 and another to 60075.1 for sorting to help out, but can't upload it here its too big.

If you would like to PM me I can email you what I have to work with.


Jan 3, 2014, 6:15 AM

Post #3 of 5 (18592 views)
Re: [AwsedreswA] Help me code this logic please [In reply to] Can't Post

The following code is untested, but should get you started.

use strict; 
use warnings;
open my $OUT, '>', 'summary.csv' or die "$!";
for my $i (0..60075){
open my $IN, '<', "$i", or die "$!";
while (my $line = <$IN>) {
my ($x, $y, $r, $g, $b) = split /\t/, $line;
next LINE unless ($x == 384 and $y == 377);
print {$OUT} "$i,$r,$g,$b\n";
close $IN;
next INFILE;
warn "Tuple not found for file $i\n";
close $IN;
close $OUT;
warn "successfully created summary.csv\n";

Good Luck,

New User

Jan 5, 2014, 6:16 AM

Post #4 of 5 (18419 views)
Re: [BillKSmith] Help me code this logic please [In reply to] Can't Post

Here is where I am at now.

It'd be nice to have progress indicator.

It would also be nice to do more than just one coordinate at a time since I have to wait forever to read off a USB 2.0 HDD. Im guessing this is hard and would require array work.

$out_file="C:\\perl\\scripts\\bluetime.txt";	# out_file is the output file name 
#$out_file="C:\\perl\\scripts\\bluetime.txt"; # uncomment and put your source here!!!!
unlink $out_file; # erased (deletes) the output file FIRST,
# otherwise it will continue to append to it!

open ($output_file,">>",$out_file) or die "Could not open output_file!!!"; #open file for append

for ($i=1;$i<=60075;$i++) # files 00000.txt thru 60075.txt
$output_name = sprintf("%05d",$i); # first field in bluetime, 5 digits

$input_file = sprintf("G:\\Frames_as_RGB_Tuples\\%05d.txt",$i); # FQ input filename
# $input_file = sprintf("C:\\perl\\scripts\\%05d.txt",$i);

open ($infile, "<",$input_file) or die "Could not open input file $input_file!!!";

## "<" means read from, ">>" means append to, ">" means write to!

# printf("G:\\Frames_as_RGB_Tuples\\%s.txt\n", $result);

while(<$infile>) # read one line from infile, put in $_
if($_ =~ /^390\t379/)
# print $_;
# print sprintf("%s\t-->%s<--\n",$output_name,$_);
print $output_file sprintf("%s\t%s",$output_name,$_); #5 digits plus tuple

close $infile;


close $output_file;

(This post was edited by AwsedreswA on Jan 5, 2014, 6:16 AM)

Veteran / Moderator

Jan 9, 2014, 11:28 PM

Post #5 of 5 (17733 views)
Re: [AwsedreswA] Help me code this logic please [In reply to] Can't Post

If you have several coordinates to check for each file, then it will be far more efficient to read each file only once and check all the coordinates during this unique reading of each file.

I would assume that the coordinates that you ar elooking for are usually coming always within a certain line number ranges. It would probably faster to discard immediately the lines that cannot give a match because they are outside the required range.

The use of the index function would probably be faster than the use of this regex:

if ($_ =~ /^390\t379/)

For monitoring the progress, you could print a message for each file being checked, or for every ten files (checking whether the file number can be divided by 10), or whatever experience will give you a satisfactory monitoring, you need to make some tries.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives