MATLAB: Analysis of png image

fluorescence microscopyimage analysisImage Processing Toolboximage segmentationMATLAB and Simulink Student Suitepng file

Hi
I´m trying to analyse images from fluorescence microscopy as png.file with an MATLAB, which I got by a college. The script starts, and all files are in a folder, which is seen by matlab, but I´m not able to open them. I´m a rooky in this stuff, so maybe here is someone who can help me.
folder_name = uigetdir; %Prompts user to select folder
filename = uigetfile; %Prompts user to select file to be analyzed
uiimport = (filename); %Imports selected file name
I = imread(filename); %Reads imported file
background = imopen(I,strel('disk', 15)); %Standardizes background and threshold
figure, surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
I2 = I – background; %Removes excess noise
imshow(I2);
level = graythresh(I2);
bw = im2bw(I2, level);
bw = bwareaopen(bw,50); %States capillary area
cc = bwconncomp(bw,4);
cc.NumObjects;
labeled = labelmatrix(cc);
whos labeled;
RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle'); %colors individual capillaries figure, imshow(RGB_label);
capillarydata = regionprops(cc,'all'); %reads all perimeter data of the capillaries
capillary_peri = [capillarydata.Perimeter];
capillary_area = [capillarydata.Area];
[min_perim, idx] = min(capillary_peri);
capillary = false(size(bw));
capillary(cc.PixelIdxList{idx}) = true;
%Converts perimeter data to micrometers
PDataInMicrons =capillary_peri*0.30120';
%Insert conversion factor here in microns per pixel
%Converts Area data to Micrometers
ADataInMicrons =capillary_area*0.0907';
%Insert conversion factor here in microns-squared per pixel-squared
nbins = 50;
figure, hist(ADataInMicrons, nbins) %Generates capillary Area histogram
title('Histogram of Capillary Area Data')
figure, hist(PDataInMicrons, nbins) %Generates capillary Perimeter histogram
title('Histogram of Capillary Perimeter Data')
SA = ADataInMicrons';
SP = PDataInMicrons';
csvwrite('AreaQuant1.csv', SA) %Writes data to area excel sheet
csvwrite('PerimQuant1.csv', SP) %Writes data to perimeter excel sheet
Thank you

Best Answer

The below modification in your code might help.
folder_name = uigetdir; %Prompts user to select folder
filename = uigetfile([folder_name, '\', '*.png']); %Prompts user to select file to be analyzed
I = imread([folder_name, '\', filename]); %Reads imported file
background = imopen(I,strel('disk', 15)); %Standardizes background and threshold
figure, surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
I2 = I - background; %Removes excess noise
imshow(I2);
level = graythresh(I2);
bw = im2bw(I2, level);
bw = bwareaopen(bw,50); %States capillary area
cc = bwconncomp(bw,4);
cc.NumObjects;
labeled = labelmatrix(cc);
whos labeled;
RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle'); %colors individual capillaries figure, imshow(RGB_label);
capillarydata = regionprops(cc,'all'); %reads all perimeter data of the capillaries
capillary_peri = [capillarydata.Perimeter];
capillary_area = [capillarydata.Area];
[min_perim, idx] = min(capillary_peri);
capillary = false(size(bw));
capillary(cc.PixelIdxList{idx}) = true;
%Converts perimeter data to micrometers
PDataInMicrons =capillary_peri*0.30120';
%Insert conversion factor here in microns per pixel
%Converts Area data to Micrometers
ADataInMicrons =capillary_area*0.0907';
%Insert conversion factor here in microns-squared per pixel-squared
nbins = 50;
figure, hist(ADataInMicrons, nbins) %Generates capillary Area histogram
title('Histogram of Capillary Area Data')
figure, hist(PDataInMicrons, nbins) %Generates capillary Perimeter histogram
title('Histogram of Capillary Perimeter Data')
SA = ADataInMicrons';
SP = PDataInMicrons';
csvwrite('AreaQuant1.csv', SA) %Writes data to area excel sheet
csvwrite('PerimQuant1.csv', SP) %Writes data to perimeter excel sheet