I am having problem un using load command.
Show older comments
I am having this problem is using load command. Anyone who can help me please?
% Extract 10 cell features for each image in 'imageInfo'
clear
tic
% nucleus area in real size
mpp_40 = 0.2525; % 40X
realMin = 80*mpp_40^2;
realMax = 1100*mpp_40^2;
realPSize = 2000*mpp_40;
% Load openslide library
openslide_load_library();
strc = load('C:/image-mRNA-prognostic-model-master/imageAndClinicalInfo/imageInfo.mat');
imInfo = strc.imageInfo;
dirData = 'C:/image-mRNA-prognostic-model-master/bin.png';
% process each image
nFile = size(imInfo, 1);
for i = 1:nFile
t1 = tic;
file = imInfo.file{i};
parts = regexp(file, '/', 'split');
filename = parts{2}(1:end-4);
% test if the image is already processed
if exist(['extractCellFeas_cellLevel/', filename, '.mat'], 'file');
fprintf('image %d/%d already processed\n', i, nFile);
continue;
end
slidePtr = openslide_open([dirData, file]);
mpp = imInfo.mppX(i);
width = imInfo.width(i);
height = imInfo.height(i);
ps = round(realPSize/mpp);
%% select patches using thumnail
% Get thumbnail
thumnail = openslide_read_associated_image(slidePtr, 'thumbnail');
thumnail = thumnail(:, :, 2:4);
[ht, wt, ~] = size(thumnail);
ratio = width/wt;
% patch size in thumbnail
pst = round(ps/ratio);
% select patches of interest in thumbnail image
[X, Y] = meshgrid(1:pst:wt-pst+1, 1:pst:ht-pst+1);
xy = [X(:), Y(:)];
d1 = size(xy, 1);
indOk = zeros(d1, 1);
for j = 1:d1
r = xy(j, 2);
c = xy(j, 1);
rows = r:r+pst-1;
cols = c:c+pst-1;
tile = thumnail(rows, cols, :);
tMean = mean(tile, 3);
if sum(tMean(:)>210) < pst*pst/2
indOk(j) = 1;
end
end
xy = xy(indOk==1, :)-1; % move upper-left point to (0, 0)
xy = round(xy*ratio);
% remvoe coordinates exceeding width or height
indOk = xy(:, 1)<=width-ps & xy(:, 2)<=height-ps;
xy = xy(indOk, :);
%% extract cell features for each tile
d1xy = size(xy, 1);
cellFeas = cell(d1xy, 1);
for ixy = 1:d1xy
x = xy(ixy, 1);
y = xy(ixy, 2);
tile = openslide_read_region(slidePtr, x, y, ps, ps, 0);
tile = tile(:, :, 2:4);
areaMin = round(realMin/mpp^2);
bw = hmt(tile, areaMin);
statsR = regionprops('table', bw, tile(:, :, 1), 'area', 'MeanIntensity',...
'MajorAxisLength', 'MinorAxisLength', 'centroid');
statsR.Area = statsR.Area*mpp^2;
statsR.MajorAxisLength = statsR.MajorAxisLength*mpp;
statsR.MinorAxisLength = statsR.MinorAxisLength*mpp;
indOk = statsR.Area <= realMax;
statsR = statsR(indOk, :);
if size(statsR, 1) < 80
continue;
end
statsG = regionprops('table', bw, tile(:, :, 2), 'MeanIntensity');
statsB = regionprops('table', bw, tile(:, :, 3), 'MeanIntensity');
statsG = statsG(indOk, :);
statsB = statsB(indOk, :);
feas1_7 = [statsR.Area, statsR.MajorAxisLength, statsR.MinorAxisLength,...
statsR.MajorAxisLength ./ statsR.MinorAxisLength,...
statsR.MeanIntensity, statsG.MeanIntensity, statsB.MeanIntensity];
% last 3 features derived from Delaunay graph
centroids = statsR.Centroid;
feas8_10 = zeros(size(statsR, 1), 3);
DT = delaunayTriangulation(double(centroids));
E = edges(DT);
for k = 1:size(centroids, 1)
edgesCell = E(sum(E==k, 2)~=0, :);
dist = zeros(size(edgesCell, 1), 1);
for m = 1:numel(dist)
p1 = centroids(edgesCell(m, 1), :);
p2 = centroids(edgesCell(m, 2), :);
dist(m) = norm(p1-p2);
end
feas8_10(k, :) = [mean(dist), max(dist), min(dist)];
end
cellFeas{ixy, 1} = [feas1_7, feas8_10*mpp];
end
cellFeas(cellfun(@isempty, cellFeas)) = []; % remove empty elements
save(['extractCellFeas_cellLevel', '/', filename, '.mat'], 'cellFeas');
fprintf('image %d/%d processed, time %f\n', i, nFile, toc(t1));
end
toc
% Close whole-slide image, note that the slidePtr must be removed manually
openslide_close(slidePtr)
clear slidePtr
% Unload library
openslide_unload_library
15 Comments
Ashish Azad
on 22 Jun 2020
Hi Muhammad,
Could you be please more specific where exactly you are getting error, and also paste the error here.
Walter Roberson
on 22 Jun 2020
dirData = 'C:/image-mRNA-prognostic-model-master/bin.png';
That already includes a file extension. Is bin.png truly a directory name or is it a file name?
file = imInfo.file{i};
parts = regexp(file, '/', 'split');
filename = parts{2}(1:end-4);
You can be sure that filename will not have any / in it, but file probably does have / in it (otherwise you would not split it)
slidePtr = openslide_open([dirData, file]);
Is file certain to start with a / ? Because dirData does not end in a / . Is file intended to be within a directory named bin.png ? Use fullfile()
Image Analyst
on 22 Jun 2020
And, you forgot to attach ''C:/image-mRNA-prognostic-model-master/imageAndClinicalInfo/imageInfo.mat"
Muhammad Adeel Ahsan Awan
on 25 Jun 2020
Steven Lord
on 25 Jun 2020
What does "this problem" mean?
- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support using the telephone icon in the upper-right corner of this page so we can investigate.
Muhammad Adeel Ahsan Awan
on 25 Jun 2020
Muhammad Adeel Ahsan Awan
on 25 Jun 2020
Walter Roberson
on 25 Jun 2020
Move the
strc = load('C:/image-mRNA-prognostic-model-master/imageAndClinicalInfo/imageInfo.mat');
To before the
openslide_load_library();
If you still have a problem with the load() crashing MATLAB then you can construct an example that does not use openslide library at all, and Mathworks will pay attention to that.
Muhammad Adeel Ahsan Awan
on 25 Jun 2020
Edited: Walter Roberson
on 25 Jun 2020
Muhammad Adeel Ahsan Awan
on 25 Jun 2020
Walter Roberson
on 25 Jun 2020
If you run in chunks then you probably did not execute the for i so probably i has its default value of sqrt(-1)
Muhammad Adeel Ahsan Awan
on 25 Jun 2020
Walter Roberson
on 25 Jun 2020
Could you confirm that if you do nothing other than run
strc = load('C:/image-mRNA-prognostic-model-master/imageAndClinicalInfo/imageInfo.mat');
at the command line, that MATLAB crashes?
Muhammad Adeel Ahsan Awan
on 25 Jun 2020
Walter Roberson
on 25 Jun 2020
You have not responded to my concerns in https://www.mathworks.com/matlabcentral/answers/551932-i-am-having-problem-un-using-load-command#comment_908500
Answers (1)
Muhammad Adeel Ahsan Awan
on 25 Jun 2020
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!