Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 4 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 21, 2011
@d-hall999 My attempt at creating 3x3 kernel to analyse surround pixels however …
…this had several drawback the edges were not included and speed was very slow.
1da18d9
@d-hall999 C source code taken from link in file, computes much faster, edges in…
…cluded, also pixel selected isnt analysed, possibility of selecting different connecting points ie 4 or 8 or even a larger shape by changing kernel.
37f238c
Commits on Mar 04, 2011
d-hall999 Switch added with user input, selects between Averaging from Neighbou…
…ring pixels or Gaussian blur.
f148703
Commits on Mar 25, 2011
@d-hall999 Convulution and Gaussian Blur smoothing filters. Smooth.m is called b…
…yy main.m
ac2e8f6
Showing with 193 additions and 0 deletions.
  1. +131 −0 Smooth.m
  2. +62 −0 convulution.m
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 REAP to reapply Smoothing to same image: ','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 'REAP'
+ 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
View
62 convulution.m
@@ -0,0 +1,62 @@
+
+% Original code taken from
+%http://stackoverflow.com/questions/3402081/test-the-surrounding-non-zeros-elements
+
+%% Clear workspace
+
+clear all
+close all
+clc
+
+%% Image Upload
+
+%image test.tif was saved in a directory found in search path
+image_1='Image_1.tif';
+
+% Reads image data
+h=imread(image_1);
+h2=h;
+
+%% User Input-Decide which smoothing filter
+
+Smoothing_Filter=input('Please enter "a" for smoothing based on average of neighbouring pixels, enter "g" for gaussian blur:','s');
+
+switch Smoothing_Filter
+ case 'a'
+
+% Convulation kernel1'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(h2),kernel,'same');
+
+% Logical operator next to array makes it calculate the number of neighbouring pixels
+nX = conv2(double(h2>=0),kernel,'same');
+
+% element by element division to get the required average
+misalign_image=sumX./nX;
+
+round(misalign_image);
+new_image=uint8(misalign_image);
+imshow(new_image);
+
+ case 'g'
+
+myfilter = fspecial('gaussian',[3 3], 0.5);
+
+myfilteredimage = imfilter(h2, myfilter, 'replicate');
+
+imshow(myfilteredimage);
+
+ otherwise
+ disp('Unknown input please enter a or g');
+
+end
+
+

No commit comments for this range

Something went wrong with that request. Please try again.