I have exposed the Gaff Chromic film and then scanned it, now in MATLAB, I have to write a code to convert it to dose and then obtain the calibration curve of the film.
Gafchromic film is a type of radiochromic film that changes color when exposed to radiation. It is used to measure the dose distribution of radiation beams in medical applications, such as radiotherapy and radiology. To convert Gafchromic film image to dose in MATLAB, you need to follow these steps:
Scan the Gafchromic film using a flatbed scanner with a high resolution and a color mode. Save the scanned image as a TIFF file.
Read the scanned image into MATLAB using the imread function. The image will be stored as an RGB matrix of uint8 values.
Convert the RGB image to a grayscale image using the rgb2gray function. The grayscale image will be stored as a matrix of double values ranging from 0 to 1.
Calibrate the grayscale image using a calibration curve that relates the pixel intensity values to the dose values. The calibration curve can be obtained by scanning and measuring the dose of several Gafchromic films with known exposures. You can use the polyfit and polyval functions to fit and evaluate a polynomial function that describes the calibration curve.
Plot the dose distribution of the Gafchromic film using the imagesc or imshow functions. You can also use the colorbar function to add a color scale that indicates the dose values.
Here is an example code that implements these steps:
% Read the scanned image
RGB = imread('gafchromic.tif');
% Convert to grayscale
I = rgb2gray(RGB);
% Calibrate using a calibration curve
% Assume that x is a vector of pixel intensity values and y is a vector of dose values
p = polyfit(x,y,2); % Fit a second-order polynomial function
D = polyval(p,I); % Evaluate the polynomial function at the grayscale values
% Plot the dose distribution
imagesc(D); % Display the dose matrix as an image
colorbar; % Add a color scale
xlabel('X (mm)'); % Add x-axis label
ylabel('Y (mm)'); % Add y-axis label
title('Dose distribution of Gafchromic film'); % Add title
For more information on how to convert Gafchromic film image to dose in MATLAB, you can refer to these links:
Image processing - TIFF images in Matlab in grayscale
Convert RGB image or colormap to grayscale - MATLAB rgb2gray
Obtain FWHM from improfile of image - MATLAB Answers
I have scanned and measured the dose of several Gafchromic films with known exposures، That is, I have some scanned images of the films exposed with different doses, but I don't know how to get their calibration curve.
And the other question is that:
(x) in the :
polyfit(x,y,2)
gives an undefined function or variable 'x' error in MATLAB.
I am glad to help you Yasaman Kiumarsi please follow this process:
First, you need to load the scanned images of the films into Matlab as matrices. You can use the imread function to do this. For example, if you have a scanned image named film1.tif in your current folder, you can load it as:
code:
film1 = imread('film1.tif');
Next, you need to extract the red, green and blue channels of the image as separate matrices. You can use the im2double function to convert the image to double precision and then use indexing to get the channels. For example:
code:
film1 = im2double(film1); % convert to double
film1_red = film1(:,:,1); % get the red channel
film1_green = film1(:,:,2); % get the green channel
film1_blue = film1(:,:,3); % get the blue channel
Then, you need to calculate the net optical density (OD) of each channel using the formula:
code:
OD = -log10(I/I0)
where I is the intensity of the irradiated film and I0 is the intensity of the unirradiated film. You need to have a scanned image of an unirradiated film as well and load it into Matlab as a matrix. For example, if you have a scanned image named film0.tif in your current folder, you can load it as:
code:
film0 = imread('film0.tif');
film0 = im2double(film0); % convert to double
Then, you can calculate the OD of each channel of film1 as:
code:
film0_red = film0(:,:,1); % get the red channel of unirradiated film
film0_green = film0(:,:,2); % get the green channel of unirradiated film
film0_blue = film0(:,:,3); % get the blue channel of unirradiated film
OD_red = -log10(film1_red./film0_red); % calculate OD for red channel
OD_green = -log10(film1_green./film0_green); % calculate OD for green channel
OD_blue = -log10(film1_blue./film0_blue); % calculate OD for blue channel
You can repeat this process for all the scanned images of the films with different doses.
Next, you need to plot the OD values against the known doses for each channel and fit a curve to them. You can use the plot function to plot the data and the polyfit function to fit a polynomial curve. For example, if you have a vector of doses named dose and a vector of OD values for the red channel named OD_red, you can plot and fit them as:
code:
plot(dose, OD_red, 'ro'); % plot data as red circles
hold on; % keep the plot on
p = polyfit(dose, OD_red, 2); % fit a second-degree polynomial curve
f = polyval(p, dose); % evaluate the polynomial at the dose values
plot(dose, f, 'r-'); % plot the fitted curve as a red line
hold off; % release the plot
You can repeat this process for all the channels and all the films.
Finally, you need to use the fitted curves to convert any OD value to dose value. You can use the polyval function to do this. For example, if you have an OD value of 0.5 for the red channel and you want to know what dose it corresponds to, you can use:
code:
dose_red = polyval(p, 0.5); % evaluate the polynomial at 0.5 OD
where p is the polynomial coefficients obtained from polyfit.
I hope this helps you with your calibration process. For more information and examples, you can check out some of these web pages: GitHub - wjcheon/EBT3_film_analyzer_Matlab: Matlab code for Gafchromic EBT3 film analysis, Efficient Protocols for Accurate Radiochromic Film Calibration and Dosimetry, Gafgui download | SourceForge.net, GitHub - jacyap/FilmProtocol: Protocol for plotting calibration curves ….
As for your other question, it seems that you have not defined or assigned any value to x before using it in polyfit. You need to make sure that x is a vector of independent variables that matches the size and shape of y, which is a vector of dependent variables. For example, if you have a vector of doses named dose and a vector of OD values for the red channel named OD_red, you can use:
code:
x = dose; % assign dose to x
y = OD_red; % assign OD_red to y
p = polyfit(x, y, 2); % fit a second-degree polynomial curve
Thank you for your patience and taking the time to respond
Your answers are thorough and
helpful I had another question,
how can I create a dose vector؟
As you mentioned :
Next, you need to plot the OD values against the known doses for each channel and fit a curve to them. You can use the plot function to plot the data and the polyfit function to fit a polynomial curve. For example, if you have a vector of doses named dose and a vector of OD values for the red channel named OD_red