Skip to content

Instantly share code, notes, and snippets.

@caner-ercan
Created August 6, 2024 20:34
Show Gist options
  • Select an option

  • Save caner-ercan/b6e617f454f5d58fa78ee9f836aa88bc to your computer and use it in GitHub Desktop.

Select an option

Save caner-ercan/b6e617f454f5d58fa78ee9f836aa88bc to your computer and use it in GitHub Desktop.
export roi
import org.apache.commons.io.FilenameUtils
def name = FilenameUtils.getBaseName(getProjectEntry().getImageName())
def server = getCurrentServer()
selectObjectsByClassification("flow")
anns =[]
def anns = getSelectedObjects()
i=0
for (ann in anns) {
def roi = ann.getROI()
def requestROI = RegionRequest.createInstance(server.getPath(), 1, roi)
def path = buildFilePath(PROJECT_BASE_DIR,"ROI",name+"_ROI"+i+".tif")
writeImageRegion(server, requestROI, path)
i=i+1
}
print name + " done"
# Check if the number of arguments is correct
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <input_folder> <output_folder>"
exit 1
fi
input_folder="$1"
output_folder="$2"
# Ensure the output folder exists
mkdir -p "$output_folder"
# Iterate over each file in the input folder
for input_file in "$input_folder"/*; do
# Get the base name of the file without the path
file_name=$(basename -- "$input_file")
# Construct the output file path
output_file="$output_folder/$file_name"
# Run the VIPS command
vips im_vips2tiff $input_file $output_file:jpeg:95,tile,pyramid
done
#!/bin/bash
# Check if the number of arguments is correct
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <input_folder> <output_folder>"
exit 1
fi
input_folder="$1"
output_folder="$2"
# Ensure the output folder exists
#mkdir -p "$output_folder"
# Function to process a single image
process_image() {
input_file="$1"
output_folder="$2"
file_name=$(basename -- "$input_file")
output_file="$output_folder/$file_name"
vips im_vips2tiff $input_file $output_file:jpeg:95,tile,pyramid
}
# Export the function to make it available to parallel
export -f process_image
# Use find to get a list of input files and pass them to parallel for processing
find "$input_folder" -type f -print0 | parallel -0 -j "$(nproc)" process_image {} $output_folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment