Info

此问题已关闭。 请重新打开它进行编辑或回答。

Creating Mask using variable threshold from an ROI, IR temp data

1 次查看(过去 30 天)
Good morning,
I apologize for posting this again but my response got flagged as potential spam. The script and image below are what I am working with currently. The script promps the user to select a threshold ROI on the image and calculates the mean and stdev. The user then selects a worm ROI. I need to create a mask that will remove the colder backgrount using the threshold ROI data. I will have to run this script on a large amount of data so the more efficient the better. I am trying to avoid converting to binary and losing the color/temp data. I am new to matlab so any help would be greatly appreciated!
Thank you in advance!!!
image:
Code:
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
load A_Mat_Files/test/12-14-22-IR-000017_1.mat; %Creates 3 files - image is Frame other 2 contain metadata
first_frame = Frame; %First frame - use to set ROIs
%We will need to always analze left-top agar pad, left bottom, right top,
%right bottom.
%You will need to click on the zoom (looks like a magnifiying glass) to
%zoom in on the image. Do this before you select ROI. After you have zoomed
%click on the magnifying glass again and then select ROI. The ROI should
%look white.
%EDIT's Made - Worm ROI, Threshold ROI, removed range of color map from
%[0:15] or [10:15] to just [] which should auto calculate it, this way the
%ROI has same colors as when selected
%---------Background Left threshold ------------------------------
close all; % Close all figure windows except those created by imtool.
imshow(first_frame,[],Colormap=jet) ; %can change the diplay range with #'s in []
title('Select ROI for Left threshold background');
hold on
roi = drawrectangle("Color","w");%draw a rectangular ROI for background
rect_lbg=roi.Position;
%xmin_lbg=round(rect(1)); %records the x-position of the upper left corner as xmin
%ymin_lbg=round(rect(2)); %records the y-position of the upper left corner as ymin
%width_lbg=round(rect(3)); %records the width of the rectangle as width
%height_lbg=round(rect(4)); %records the length of the rectangle as length
%Store info about the rectangle ROI as we will need them for the frames after frame 1
thres_lbg=imcrop(first_frame,rect_lbg); % crops the image and stores the smaller image in thres_bg
subplot(1,2,1); % plots the cropped and original images side by side so you can make sure they are right
imshow(first_frame,[],Colormap=jet);
title('Original Image')
subplot(1,2,2);
imshow(thres_lbg,[],Colormap=jet);
title('Left Threshold Cropped');
mean_thres_lbg = mean2(thres_lbg); % calculate the mean temp of the background by determining mean of the cropped image
std_thres_lbg= std2(thres_lbg); % calculate the std of the temp of the background by determining std of the cropped image
max_thres_lbg = max(thres_lbg,[],"all"); % calculate the max temp of the background by determining max of the cropped image
min_thres_lbg = min(thres_lbg,[],"all"); % calculate the min temp of the background by determining min of the cropped image
pause; %Allows user to examine cropped and uncropped images to see if the ROI is ok. Hit any key to continue.
%---------------------Worm 1 (left side - worm to the left)----------------
close all; % Close all figure windows except those created by imtool.
imshow(first_frame,[],Colormap=jet) ; %can change the diplay range with #'s in []
title('Select ROI for Left Worm 1 - leftmost worm');
hold on
roi = drawrectangle("Color","w");%draw a rectangular ROI for worm 1 using mouse
rect_lw1=roi.Position;
%xmin_lw1=round(rect(1)); %records the x-position of the upper left corner as xmin
%ymin_lw1=round(rect(2)); %records the y-position of the upper left corner as ymin
%width_lw1=round(rect(3)); %records the width of the rectangle as width
%height_lw1=round(rect(4)); %records the length of the rectangle as length
%Store info about the rectangle ROI as we will need them for the frames after frame 1
Worm_lw1=imcrop(first_frame,rect_lw1); % crops the image and stores the smaller image in Worm_lw1
subplot(1,2,1); % plots the cropped and original images side by side so you can make sure they are right
imshow(first_frame,[],Colormap=jet);
title('Original Image')
subplot(1,2,2);
imshow(Worm_lw1,[],Colormap=jet);
title('Cropped Image for Left Side Worm1 (Leftmost Worm1)');
mean_Worm_lw1 = mean2(Worm_lw1); % calculate the mean temp of the worm by determining mean of the cropped image
std_Worm_lw1 = std2(Worm_lw1); % calculate the std of the temp of the worm by determining std of the cropped image
max_Worm_lw1 = max(Worm_lw1,[],"all"); % calculate the max temp of the worm by determining max of the cropped image
min_Worm_lw1 = min(Worm_lw1,[],"all"); % calculate the min temp of the worm by determining min of the cropped image
pause; %Allows user to examine cropped and uncropped images to see if the ROI is ok. Hit any key to continue.

回答(0 个)

此问题已关闭。

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by