gpt-4-0314· openai
Suzhen/CodeChat
please write an imagej macro script that turns a gray image into a colored one using a…
- User
please write an imagej macro script that turns a gray image into a colored one using a custom lookup table.
- Assistant
Here's an ImageJ macro script that converts a grayscale image into a colored one using a custom lookup table:
// Generate custom LUT custom_LUT = newArray(256*3); for (i=0; i<256; i++) { custom_LUT[i] = 255 - i; // Red channel custom_LUT[i+256] = i; // Green channel custom_LUT[i+512] = (i >= 128) ? 255 : 0; // Blue channel } // Ask user for a gray image file_path = File.openDialog("Select a grayscale image"); if (file_path == "") { exit("No file was selected."); } // Open the image open(file_path); // Check if the image is grayscale (8-bit or 16-bit) imageTitle = getTitle(); imageType = getPixelSize(); if ((imageType != 8 && imageType != 16) || isRGB()) { close(); exit("Please select a grayscale (8-bit or 16-bit) image."); } // Apply the custom LUT run("RGB Color"); setLut(custom_LUT); // Apply the custom lookup table after conversion to RGB // Save the generated image save_dir = getDirectory("image"); save_path = save_dir + "Colored_" + imageTitle; saveAs("Tiff", save_path); print("Colored image saved as:", save_path); close();
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.