//bpm extraction from kymographs with log saving || Luís Marques //housekeeping, clear log + results //print("\\Clear"); run("Clear Results"); do { //open video file from phone, manually assign fps run("Close All"); path = File.openDialog("Select a video file to be analyzed"); run("Movie (FFMPEG)...", "choose=path use_virtual_stack first_frame=0 last_frame=-1"); fps = getNumber("At which framerate was this video acquired?", 60); name = getString("What's the name of this sample", ""); rename(name); frames = nSlices; //zoom in on heart and draw line for kymograph setTool("zoom"); waitForUser("Click to zoom in on heart.\nPress ok to continue"); setTool("line"); waitForUser("Click and drag to draw a small line perpendicular to heartbeat motion.\nPress ok to continue"); //make kymograph and window housekeeping run("Reslice [/]...", "output=1.000 slice_count=1 rotate avoid"); rename("kymograph"); run("8-bit"); run("Enhance Contrast", "saturated=0.35"); run("Size...", "width="+frames+" height=65 depth=1 average interpolation=Bicubic"); selectWindow(name); close(); //manually select 5 beats setTool("rectangle"); waitForUser("Draw a rectangle encompassing 5 events. Press ok to continue"); run("Crop"); //calculate bpm from previous info frames_5beats = getWidth(); seconds_5beats = frames_5beats / fps; bpm = 300 / seconds_5beats; //print(name+" has a heartrate of "+bpm); //housekeeping selectWindow("kymograph"); close(); // Populate Output Table tbl_out = "BPM Counts"; if(isOpen(tbl_out)){ //check number of table entries and set entry at index number tabsize = Table.size; //print(tabsize); Table.set("Label", tabsize, name); Table.set("BPM", tabsize, bpm); Table.update; } else{ // Create new table and generate first entry Table.create(tbl_out); Table.set("Label", 0, name); Table.set("BPM", 0, bpm); Table.update; } //boolean to measure more samples bool = getBoolean("Would you like to do another one?"); } while (bool==true); //if end of measurements, saves and closes the Results table if (bool==false){ dirout = getDirectory("Choose where you want to save the Results table"); resultsname = getString("What do you want to call this Results file?", ""); selectWindow("BPM Counts"); saveAs("Results", dirout + resultsname + ".csv"); close(resultsname + ".csv"); beep(); waitForUser("All done"); }