% This programs crops the input image to user specified rectangular area. Then
% it finds the centroid of the cropped /new image. Once the centroid is determined
% it extracts the pixel values in both directions, smoothens & calculate FWHM in individual directions.
% Finally it saves the FWHMs in a data file with image number.
clear all;
clc;
InputFile = '0';% Write common part of the file name
% InputImage = input('write name of the image');% Load an image to a matrix
% Image = imread(InputImage);
nDataFile = 21;% total number of data files to be analyzed
OutPut = zeros(nDataFile,3); % 1st col: file no, 2nd col: FWHM-X
% 3rd cplumn : FWHM-Y
for i = 2:nDataFile
if(i<10)
InputImage=imread(strcat(InputFile,'0',num2str(i),'.bmp'));
else
InputImage=imread(strcat(InputFile,num2str(i),'.bmp'));
end
% Select a rectangular region of interest (try to keep it general i.e. valid for all figures)
if i == 2
figure
imshow(InputImage)
rect = getrect
end
% Crop image as per user defined rectangle
% (Do it interactively for the 1st time, to estimate
% the coordinates of the recangle)
% place a condition here, when analyzing multiple
% images, the ractangle has to be defined for the
% 1st time only
CroppedImage = imcrop(InputImage, rect);
imshow(CroppedImage);
CroppedImageSize = size(CroppedImage) % Size of the cropped image,basically the matrix dimension
% that you are going to deal with
%Find the centroid of the Image ( The subroutine calculates
% the centriod of the image by calculating the averaging the pixel
% values in elimentary way. This is obtained from MATLAB CENTRAL file
% exchange websiteused and is used on "as is" basis. So check it
% before you use it.
[meanx, meany] = centroid(CroppedImage)
% Now that the centroid of the image is found, pick all the pixel
% values along individual axis & store it variables. These variables
% have to smoothened and then FWHM has to be determind from them.
linex = CroppedImage(:,round(meany)); % selects line along X-direction
liney = CroppedImage(round(meanx),:); % " " " Y- "
plot(linex)
figure
plot(liney)
% % Now smoothen linex & liney before determining the maximas & minimas
% Smoothlinex = smooth(linex,'moving');
% Smoothliney = smooth(liney,'moving');
% Determine maximum & Minimum values from both the data & Normalize
% each 1D array
% Normalizedlinex = (linex ./max(linex));
% Normalizedliney = (liney ./max(liney));
% Determine FWHM in both directions
indx = find(linex == round((max(linex)-min(linex))/2))
FWHMlinex = abs(max(indx)-min(indx))
indy = find(liney == round((max(liney)-min(liney))/2))
FWHMliney = abs(max(indy)-min(indy))
OutPut(i,1) = i
OutPut(i,2) = FWHMlinex;
OutPut(i,3) = FWHMliney;
% pause
end
dlmwrite('FSonCVIDMdimensions012908.dat',OutPut);