Averaging the values of grayscale intensity for each image?

1 view (last 30 days)
Is there a way in my script to just get each individual image's ControltoTest without overwriting it every time it analyzes an image for a value and just do the average mean of the values?
RC = input('Are all the images cropped already? Y/N','s');
if strcmpi(RC, 'y')
uncropped=1;
else
uncropped=0;
end
%Asks user to select the folder containing the calibration set inside.
CalFolder = uigetdir('Please select the calibration folder containing the images to calibrate.');
if ~isdir(CalFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', CalFolder);
uiwait(warndlg(errorMessage));
return;
end
%Adds the folder pathname to the top of the MATLAB search path list so it can find it first.
addpath(CalFolder);
%Returns a string containing the full file pathname and then shows the
%filenames of the pictures inside the folder.
calfilePattern = fullfile(CalFolder, '*.jpg');
caljpegFiles = dir(calfilePattern);
%Creates a cell array with the dimensions of: the quantity of pictures in
%the folder by 1
LFAcalarr=cell(length(caljpegFiles),1);
%Stores the filenames of the pictures to use in the script.
for i=1:length(caljpegFiles)
LFAcalarr{i}=caljpegFiles(i).name;
end
%Insert file names (without extensions) into LFAfile for processing needs
%all images in folder.
for m=1:length(LFAcalarr)
%Add the file extension and look for the file
LFACalibration = imread(LFAcalarr{m});
%Uncropped set to 0 means that the image must still be manually
%cropped
if(uncropped==0)
%Image will appear in upper panel.
%Manually crop by drawing a box around the test and control lines
%Make sure the control line is in the left half of the crop window
%and the test line is in the right half of the crop window
subplot(3,1,1);
LFAGrayCal = imcrop(rgb2gray(LFACalibration));
close all;
else
LFAGrayCal = rgb2gray(LFACalibration);
end
%Get the number of pixels along the x axis
CropWidthCal = size(LFAGrayCal,2);
%Convert to 1-Dimension by averaging along the columns
%In Grayscale, low values correspond to dark and high values to white
%Take complement and add 255 so dark values correspond to high signals
LFA1DCal=imcomplement(mean(LFAGrayCal,1))+255;
%Split the left matrix containing control line
%Split right matrix containing test line
LFAControlCal = LFA1DCal(1:fix(0.5*CropWidthCal));
LFATestCal = LFA1DCal(fix(0.5*CropWidthCal)+1:CropWidthCal);
%Locate the control line by finding the maximum and get value
[CalControlLineMax, CalControlLineLocation] = max(LFAControlCal);
%Calibration is on
%Locate test line by finding the maximum and get value
[TestLineMaxCal,TestLineLocationCal] = max(LFATestCal);
TestLineLocationCal = TestLineLocationCal + fix(.5*CropWidthCal);
%Calculate distance between control and test line
ValControlToTest=TestLineLocationCal-CalControlLineLocation;
ControlToTest = mean(ValControltoTest);
end
_

Accepted Answer

Image Analyst
Image Analyst on 9 Jul 2014
Make it an array
ControlToTest(m) = ..................
  2 Comments
Bryant
Bryant on 9 Jul 2014
Thanks for the response Image Analyst, I got this error
Undefined function 'ControltoTest' for input arguments of type 'double'.
Error in Calibration_Script (line 78)
ControlToTest = mean(ControltoTest(m));
Image Analyst
Image Analyst on 9 Jul 2014
?Huh? Why is it not
ControlToTest(m) = mean(ValControltoTest);

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!