I have 3D imaging stacks that I'd like to investigate individual images from within the image stacks. I have found the mean intensity for each image and now would like to subtract this mean from all pixels within that image. I want to do this for all images within the stack and then show the image stack. I've tried using imsubtract, but I'm getting matrix mismatch errors. Here's the code in question.
% Request file selection.
[fileNameF pathNameF] = uigetfile('*C0*.tiff');filePathF = fullfile(pathNameF, fileNameF);disp(fileNameF);filePathB = strrep(filePathF, 'C0', 'C1');%Input wavelength, etc.
prompt = {'Calibration ratio:', 'Lower threshold', 'Upper threshold', 'Z step size [um]'};dlg_title = 'Inputs';num_lines = 1;if exist('fbdefaults2.mat', 'file') load('fbdefaults2.mat', 'def');else def = {'1','6', '254', '1'};endanswer = inputdlg(prompt,dlg_title,num_lines,def);fbCalibrationRatio=str2num(answer{1});lowerThreshold=str2num(answer{2});upperThreshold=str2num(answer{3});zStepSize=str2num(answer{4});def=answer;save('fbdefaults2.mat', 'def');info=imfinfo(filePathF);slices = length(info);height=info(1).Height;width=info(1).Width;fAttVecMean=zeros(1,slices);bAttVecMean=zeros(1,slices);newIfmean=zeros(1,slices);for slice=1:slices If = (imread(filePathF, slice)) Ib = (imread(filePathB, slice)) %Thresholding the images within the stack
mask = find((If < lowerThreshold) | (If > upperThreshold)); If(mask)=NaN; %Ib(mask)=NaN;%Stringent condition.
mask = find((Ib < lowerThreshold) | (Ib > upperThreshold)); Ib(mask)=NaN; %If(mask)=NaN;%Stringent condition.
fAttVal = nanmean(If(:)); bAttVal = nanmean(Ib(:)); fAttVecMean(1,slice)=fAttVal; bAttVecMean(1,slice)=bAttVal; IfDif(1,slice)=imsubtract(If,fAttVecMean); end
Thanks for the assistance!
Best Answer