Analysis of png image

7 views (last 30 days)
Christian Dippel
Christian Dippel on 4 Nov 2020
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

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 4 Nov 2020
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
  2 Comments
Christian Dippel
Christian Dippel on 4 Nov 2020
Thank you very much, but unfortunaly it did not work.
Subhadeep Koley
Subhadeep Koley on 4 Nov 2020
Can you provide the exact error message, which you're getting?

Sign in to comment.

More Answers (1)

Christian Dippel
Christian Dippel on 4 Nov 2020
When I start the script, a window appears, where I select the folder. I select it. Then appears the next window, where I should select a file. But all files are pale and unselectable. So I click cancel. Then I get the following error text.
Error in imread (line 377)
fullname = get_full_filename(filename);
Error in QuantUnsort2 (line 3)
I = imread([folder_name, '\', filename]); %Reads imported file
  1 Comment
Christian Dippel
Christian Dippel on 4 Nov 2020
Hi now I noticed an other mistake by my self. Thank you very much.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!