필터 지우기
필터 지우기

Averaging the values of grayscale intensity for each image?

조회 수: 3 (최근 30일)
Bryant
Bryant 2014년 7월 9일
댓글: Image Analyst 2014년 7월 9일
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
_

채택된 답변

Image Analyst
Image Analyst 2014년 7월 9일
Make it an array
ControlToTest(m) = ..................
  댓글 수: 2
Bryant
Bryant 2014년 7월 9일
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 2014년 7월 9일
?Huh? Why is it not
ControlToTest(m) = mean(ValControltoTest);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by