Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Wait for the gel image to open
- waitForImage();
- // Display a message and prompt the user to draw a rectangle around the gel
- waitForUser("Draw a rectangle around the gel");
- // Get the ROI (Region of Interest) of the gel
- getSelectionBounds(x, y, width, height);
- // Check if a valid ROI has been selected
- if (width > 0 && height > 0) {
- // Select the ROI
- makeRectangle(x, y, width, height);
- // Calculate the mean intensity value within the ROI
- run("Measure");
- // Get the mean intensity value
- var mean = getResult("Mean", 0);
- // Check if the mean intensity value is valid
- if (mean > 0) {
- // Normalize the image by dividing it by the mean intensity value
- run("Divide...", "value=" + mean);
- // Enhance the contrast and display the normalized image
- run("Enhance Contrast", "saturated=0.35");
- // Create a copy of the original gel image
- selectWindow("Original gel");
- run("Duplicate...", "title=Original_gel");
- // Display a message and prompt the user to select the bands of interest
- waitForUser("Use the 'Rectangular' tool to select the bands of interest");
- // Create a list to store the coordinates of the selected bands
- var bandCoords = [];
- // Loop for the user to select multiple bands of interest
- while (true) {
- // Wait for the user to select a band of interest
- waitForSelection("rectangle");
- // Get the coordinates of the selection
- getSelectionBounds(x_band, y_band, width_band, height_band);
- // Check if a valid band has been selected
- if (width_band > 0 && height_band > 0) {
- // Store the coordinates of the selected band in the list
- bandCoords.push([x_band, y_band, width_band, height_band]);
- // Draw the lines selected by the user on the graph
- setForegroundColor(255, 0, 0); // Red color
- drawLine(x_band, y_band + height_band / 2, x_band + width_band, y_band + height_band / 2);
- drawLine(x_band, y_band + height_band / 2 - 1, x_band + width_band, y_band + height_band / 2 - 1);
- drawLine(x_band, y_band + height_band / 2 + 1, x_band + width_band, y_band + height_band / 2 + 1);
- } else {
- // No valid band selected, end the selection process
- if (bandCoords.length === 0) {
- showError("Error: No bands of interest have been selected.");
- }
- break;
- }
- }
- // Check if bands of interest have been selected
- if (bandCoords.length > 0) {
- // Create a plot with the normalized intensity values
- newPlot("Normalized Intensity Profile", "Position", "Intensity");
- // Process each selected band
- for (var i = 0; i < bandCoords.length; i++) {
- var band = bandCoords[i];
- var x_band = band[0];
- var y_band = band[1];
- var width_band = band[2];
- var height_band = band[3];
- // Select the band of interest
- makeRectangle(x_band, y_band, width_band, height_band);
- // Calculate the normalized intensity profile in the selected band
- run("Plot Profile");
- // Get the normalized intensity values
- var intensityArray = newArray(width_band);
- getProfile(intensityArray);
- // Add the normalized intensity values to the plot
- addValues("Normalized Intensity Profile", newArray(width_band), intensityArray);
- }
- // Save the original gel image
- selectWindow("Original_gel");
- var originalGelPath = getPath("Save");
- if (originalGelPath) {
- saveAs("Tiff", originalGelPath);
- } else {
- showError("Error: No valid location has been selected to save the original gel image.");
- }
- // Save the plot
- selectWindow("Normalized Intensity Profile");
- var graphPath = getPath("Save");
- if (graphPath) {
- saveAs("PNG", graphPath);
- } else {
- showError("Error: No valid location has been selected to save the plot.");
- }
- // Save the normalized gel image
- selectWindow("Normalized gel");
- var normalizedGelPath = getPath("Save");
- if (normalizedGelPath) {
- saveAs("Tiff", normalizedGelPath);
- } else {
- showError("Error: No valid location has been selected to save the normalized gel image.");
- }
- // Display a success message with the saved files
- showSuccess("Process completed. The original gel image, normalized gel image, and plot have been saved.");
- } else {
- showError("Error: No valid bands of interest have been selected.");
- }
- } else {
- showError("Error: The mean intensity value is zero or negative. The image cannot be normalized.");
- }
- } else {
- showError("Error: No valid region of interest has been selected.");
- }
- // Function to display an error message
- function showError(message) {
- showMessage("Error", message, "Error");
- }
- // Function to display a success message
- function showSuccess(message) {
- showMessage("Success", message, "Information");
- }
- // Generic function to display a message
- function showMessage(title, message, type) {
- IJ.showMessage(title, message, type);
- }
- // Function to prompt the user for a location and file name to save
- function getPath(action) {
- var dialog = FileDialog(action);
- dialog.setVisible(true);
- var selectedPath = dialog.getDirectory() + dialog.getFileName();
- return selectedPath !== "nullnull" ? selectedPath : null;
- }
Advertisement
Comments
-
Comment was deleted
-
- Wait for the gel image to open.
- Ask the user to draw a rectangle around the gel.
- Get the coordinates of the Region of Interest (ROI) of the gel.
- Check if a valid ROI has been selected.
- If a valid ROI has been selected, perform the following actions:
- a. Select the ROI in the image.
- b. Calculate the mean intensity value within the ROI.
- c. Check if the mean intensity value is valid.
- d. If the mean intensity value is valid, normalize the image by dividing it by the mean value.
- e. Enhance the contrast of the normalized image and display it.
- f. Create a copy of the original gel image.
- g. Ask the user to select the bands of interest in the normalized gel.
- h. Store the coordinates of the selected bands.
- i. Display the selected bands on the graph.
- j. Calculate and display the normalized intensity profile for each selected band.
- k. Save the original gel image, the graph, and the normalized image to files.
- l. Display a success message indicating that the files have been saved.
- If a valid ROI has not been selected, display an error message.
- If the mean intensity value is zero or negative, display an error message.
- If no valid bands of interest have been selected, display an error message.
- In summary, this program automates the processing of gel images, normalizes the intensity of the image, allows the user to select and analyze bands of interest, and saves the results to files.
Add Comment
Please, Sign In to add comment