Permalink
Browse files

Running version files are individual functions called by main.m

  • Loading branch information...
d-hall999 committed Mar 25, 2011
1 parent 26475f0 commit 11ee6a8b1c6d492669ef62d5804a58711bf670c0
Showing with 484 additions and 8 deletions.
  1. +69 −0 FRI.m
  2. +51 −0 Istack.m
  3. BIN MyColormaps.mat
  4. +131 −0 Smooth.m
  5. +212 −0 background.m
  6. +4 −8 main.m
  7. +17 −0 normalize.m
View
69 FRI.m
@@ -0,0 +1,69 @@
+function [ratio1,ratio2,ratio3]=FRI(image_stack_n)
+[~,~,Z]=size(image_stack_n);
+
+
+ for Z=1:Z; % selects image from its z value
+
+double_array_{Z}=image_stack_n(:,:,Z); %creates array with an image in each cell
+
+
+ end
+
+
+%image division 1st channel/2nd Channel
+
+
+ratio1=double_array_{1}./double_array_{2};
+
+%finds where denominator image is present but no value in numerator
+[Y,X]=find(ratio1==0);
+zeroidx=sub2ind(size(ratio1),Y',X');
+ratio1(zeroidx)=0.1;
+
+%h=find(ratio1>0 & ratio1<0.1);
+% zeroidx=sub2ind(size(ratio1),Y',X');
+%ratio1(h)=0.1;
+
+%finds where numerator image is present but no value in numerator
+[Y,X]=find(ratio1>10);
+infidx=sub2ind(size(ratio1),Y',X');
+ratio1(infidx)=10;
+
+ratio1=log10(ratio1);
+
+%image division 1st channel/3rd channel
+ratio2=double_array_{1}./double_array_{3};
+
+[Y,X]=find(ratio2==0);
+zeroidx=sub2ind(size(ratio2),Y',X');
+ratio2(zeroidx)=0.1;
+
+%h=find(ratio2>0 & ratio2<0.1);
+% zeroidx=sub2ind(size(ratio2),Y',X');
+%ratio2(h)=0.1;
+
+[Y,X]=find(ratio2>10);
+infidx=sub2ind(size(ratio2),Y',X');
+ratio2(infidx)=10;
+
+ratio2=log10(ratio2);
+
+%image division 2nd channel/3rd channel
+
+ratio3=double_array_{2}./double_array_{3};
+
+[Y,X]=find(ratio3==0);
+zeroidx=sub2ind(size(ratio3),Y',X');
+ratio3(zeroidx)=0.1;
+
+%h=find(ratio3>0 && ratio3<0.1);
+% zeroidx=sub2ind(size(ratio3),Y',X');
+%ratio2(h)=0.1;
+
+[Y,X]=find(ratio3>10);
+infidx=sub2ind(size(ratio3),Y',X');
+ratio3(infidx)=10;
+
+ratio3=log10(ratio3);
+
+end
View
@@ -0,0 +1,51 @@
+function [image_stack_reg]=Istack(image_stack)
+image_stack1=image_stack;
+C=0;
+while C==0
+image_stack1=image_stack;
+
+stack_q=input('Do you wish to auto align images. Y for Yes, N for No: ','s');
+
+switch stack_q;
+
+ case 'Y'
+% Function runs StackReg macro so user doesn't have to use ImageJ interface
+
+MIJ.createImage(image_stack1); % exports stack to Image J
+MIJ.run('StackReg ', 'transformation=[Translation]'); % Runs StackReg
+image_stack1=MIJ.getCurrentImage(); %imports aligned stack to image J
+image_stack_reg=uint16(image_stack1); %converts i age stack back to uint16
+
+ case 'N'
+ image_stack_reg=image_stack1;
+
+ otherwise
+ C=0;
+end
+%=========================================================================
+% Plots stacked images Images
+
+%finds max for subplots
+[h,~] = max(image_stack_reg(:));
+[~,~,Z]=size(image_stack_reg);
+% Image_Presentation
+ for Z=1:Z; % selects image from its z value
+
+image_{Z}=image_stack_reg(:,:,Z);
+subplot(2,2,Z);imshow(image_{Z},[0 h]);
+
+ end
+ disp('Please check image stack is correctly aligned in ImageJ!!!!!');
+ stack_happy=input('Are you happy with stack. Y for Yes. N for No: ','s');
+
+ switch stack_happy
+ case 'Y'
+ C=1;
+ case 'N'
+ C=0;
+ otherwise
+ disp('Unknown input beginning Smoothing for image slice again')
+ C=0;
+ end
+ end
+end
View
Binary file not shown.
View
131 Smooth.m
@@ -0,0 +1,131 @@
+function [image_stack_s]=Smooth(image_stack_b)
+
+cd 'Smoothing'
+[~,~,Z]=size(image_stack_b);
+
+% User Input-Decide which smoothing filter
+
+for Z=1:Z; % selects image from its z value
+image_slice=image_stack_b(:,:,Z);
+
+
+% This starts loop as if user was unhappy about image
+C=0;
+count=1;
+while C==0 || User_Error==0 %this loop allows user to change filter if unhappy about analysed image
+% If input incorrect starts loop regardless wether user inputs 1 or 0
+
+count_text=['Applied smoothing filter to this image ',num2str(count),' before'];
+disp(count_text);
+%Asks user for input
+Smoothing_Filter=input('Please enter "A" for smoothing based on average of neighbouring pixels or enter "G" for gaussian blur:','s');
+
+
+
+switch Smoothing_Filter %switch allowing user to select smoothing filter
+%========================================================================
+ case 'A'
+close all
+% Convulation kernel's correspond to neighbouring pixels 0 is pixel
+% currently selected during computation
+% 1 1 1
+% 1 0 1
+% 1 1 1
+kernel = [1 1 1;1 0 1;1 1 1];
+
+%This computes sum of neighbouring pixels
+sumX= conv2(double(image_slice),kernel,'same');
+
+% Logical operator next to array makes it calculate the number of neighbouring pixels
+nX = conv2(double(image_slice>=0),kernel,'same');
+
+% element by element division to get the required average
+smoothed_image=sumX./nX;
+
+% Selects Max intensity value of uint16 image
+[h,~] = max(image_slice(:));
+
+% Allows manipulation of figure and Subplot
+figure_1=figure;SP1=subplot(1,2,1);imshow(image_slice,[0 h]);
+% Set figure size, Positon
+set(figure_1,'Position',[10 10 800 800]);
+set(SP1,'Position',[0.05 0.05 0.45 0.96]);
+
+% Converts image back to 16-bit and sets brightness
+round(smoothed_image);
+J=uint16(smoothed_image);
+[h,~] = max(J(:));
+
+% Defines suplot & its position
+SP2=subplot(1,2,2);imshow(J,[0 h]);
+set(SP2,'Position',[0.53 0.05 0.45 0.96]);
+User_Error=1;
+Print_Text='Average from Neighbouring cells ';
+%==========================================================================
+
+ case 'G' %user selects gaussian blur
+g_size=input('Please enter size of gaussian square: ');
+myfilter = fspecial('gaussian',[g_size,g_size], 0.5);% selects gaussian and size,
+J = imfilter(image_slice, myfilter, 'replicate');% filters image
+
+% Selects Max intensity value of uint16 image
+[h,~] = max(image_slice(:));
+
+% Allows manipulation of figure and Subplot
+figure_1=figure;SP1=subplot(1,2,1);imshow(image_slice,[0 h]);
+% Set figure size, Positon
+set(figure_1,'Position',[50 10 1120 840]);
+set(SP1,'Position',[0.05 0.05 0.45 0.96]);
+
+% Displays subplot 2
+[h,~] = max(J(:));
+SP2=subplot(1,2,2);imshow(J,[0 h]);
+set(SP2,'Position',[0.53 0.05 0.45 0.96]);
+User_Error=1;
+Print_Text=['Gaussian blur, size: ',num2str(g_size),' '];
+%==========================================================================
+
+ otherwise % minimize errors from user
+ disp('Unknown input!!! please enter a or g: ');
+ User_Error=0;
+
+end
+disp('Please ensure you if you redo that you use same method and same size if using gaussian blur');
+User_happy=input('Please enter Y if you are happy with image, enter N to start smoothing from original image, \n enter REDO to apply Smoothing again: ','s');
+
+switch User_happy
+ case 'Y'
+ C=1;
+ image_text=['Applied ', Print_Text,num2str(count),' times'];
+ fig_to_file=figure;imshow(J, [0 h]);
+ TXT=text(20,20,image_text);
+ set(TXT,'color',[1 0 0]);
+ print(fig_to_file, '-dtiffn',files{Z});
+
+ case 'N'
+ C=0;
+ image_slice=image_stack_b(:,:,Z);
+ count=1;
+ case 'REDO'
+ C=0;
+ image_slice=J;
+ count=count+1;
+ otherwise
+ disp('Unknown input beginning Smoothing for image slice again')
+ C=0;
+end
+
+
+
+end
+image_stack_s(:,:,Z)=J;
+
+% clear variables not need
+clear kernel
+clear sumX
+clear nX
+clear smoothed_image
+clear location
+clear J
+
+end
Oops, something went wrong.

0 comments on commit 11ee6a8

Please sign in to comment.