Skip to content
Snippets Groups Projects
Commit cc0a450b authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Blobs: added mask creation and loading for difblobs

parent f009ff88
No related branches found
No related tags found
No related merge requests found
function gtConvertRawImages2Blobs(acq_name, first, last)
function gtConvertRawImages2Blobs(parameters, first, last)
if (~exist('parameters', 'var'))
parameters = gtMATVolReader('parameters.mat:parameters');
end
if (~exist('first', 'var'))
first = 1;
end
difblob_num = mym(['select count(*) from ' acq_name 'difblob']);
difblob_num = mym(['select count(*) from ' parameters.acq.name 'difblob']);
if (~exist('last', 'var'))
last = difblob_num;
end
......@@ -11,10 +15,11 @@ function gtConvertRawImages2Blobs(acq_name, first, last)
stats = GtTasksStatistics();
stats.add_task('load_blob', 'Time to load from DB');
stats.add_task('load_mask', 'Time to load mask');
stats.add_task('save_blob', 'Time to save to HDF5');
stats.add_task('convert_blob', 'Time for converting from DB to HDF5')
table_difspot = sprintf('%sdifspot', acq_name);
table_difspot = sprintf('%sdifspot', parameters.acq.name);
fprintf('Progress: ')
c = tic();
......@@ -27,8 +32,13 @@ function gtConvertRawImages2Blobs(acq_name, first, last)
blob(blob < 0) = 0;
stats.toc('load_blob')
stats.tic('load_mask')
mask = get_mask('2_difspot', ii, size(blob, 3), parameters);
mask(mask < 0) = 0;
stats.toc('load_mask')
stats.tic('save_blob')
gtWriteBlobToHDF5('2_difblob', ii, blob, bb);
gtWriteBlobToHDF5('2_difblob', ii, blob, bb, mask);
stats.toc('save_blob')
stats.toc('convert_blob')
......@@ -58,3 +68,18 @@ function [blob, bb] = get_blob(table_difspot, difspotID, info)
blob(:, :, s_ii) = edf_read(filename, GT_bb, false, info);
end
end
function mask = get_mask(spot_dir, blob_id, depth_blob, parameters)
if (parameters.seg.writeblobs)
mask = gtDBBrowseDiffractionVolume(parameters.acq.name, blob_id);
mask = mask ~= 0;
else
sub_dir = fullfile(spot_dir, sprintf('%05d', blob_id - mod(blob_id, 1e4)));
filename = fullfile(sub_dir, sprintf('difspot%05d.edf', blob_id));
mask = edf_read(filename) ~= 0;
mask = mask(:, :, ones(1, depth_blob));
end
end
function [blob_vol, blob_bb] = gtReadBlobFromHDF5(blob_dir, blob_id)
% [blob_vol, blob_bb] = gtReadBlobFromHDF5(blob_dir, blob_id)
function [blob_vol, blob_bb, blob_mask] = gtReadBlobFromHDF5(blob_dir, blob_id)
% [blob_vol, blob_bb, blob_mask] = gtReadBlobFromHDF5(blob_dir, blob_id)
if (~exist('blob_dir', 'var') || isempty(blob_dir))
blob_dir = '2_difblob';
end
sub_dir = fullfile(blob_dir, sprintf('%06d', blob_id - mod(blob_id, 1e4)));
fnameout = fullfile(sub_dir, sprintf('difblob_%06d.hdf5', blob_id) );
if (isempty(dir(fnameout)))
......@@ -9,9 +12,13 @@ function [blob_vol, blob_bb] = gtReadBlobFromHDF5(blob_dir, blob_id)
end
blob_vol = h5read(fnameout, '/rawblob');
if (nargout == 2)
if (nargout >= 2)
blob_bb = h5readatt(fnameout, '/rawblob', 'bb');
blob_bb = [blob_bb(2:3:end), blob_bb(1:3:end), blob_bb(3:3:end)];
blob_bb = double([blob_bb(1, :), blob_bb(2, :)]);
end
if (nargout >= 3)
blob_mask = h5read(fnameout, '/mask');
blob_mask = logical(blob_mask);
end
end
\ No newline at end of file
......@@ -474,7 +474,7 @@ function sfWriteBlob(blob, stack)
blob_bb = blob.bb;
% put z into reference of the dataset
blob_bb(3) = blob_bb(3) + stack.first - 1;
gtWriteBlobToHDF5(stack.difblobdir, blob.difblobID, blob.rawgreyvol, blob_bb);
gtWriteBlobToHDF5(stack.difblobdir, blob.difblobID, blob.rawgreyvol, blob_bb, blob.greyvol ~= 0);
end
if (stack.writespots)
......
function gtWriteBlobToHDF5(blob_dir, blob_id, blob_vol, blob_bb)
function gtWriteBlobToHDF5(blob_dir, blob_id, blob_vol, blob_bb, blob_mask)
sub_dir = fullfile(blob_dir, sprintf('%06d', blob_id - mod(blob_id, 1e4)));
if (~exist(sub_dir, 'dir'))
[status, message, messageid] = mkdir(sub_dir);
......@@ -16,8 +16,15 @@ function gtWriteBlobToHDF5(blob_dir, blob_id, blob_vol, blob_bb)
vol_size = [size(blob_vol, 1) size(blob_vol, 2) size(blob_vol, 3)];
chunk_size = min([16 16 4], vol_size);
h5create(fnameout, '/rawblob', vol_size, 'Datatype', 'single', 'Deflate', 1, 'ChunkSize', chunk_size);
% h5create(fnameout, '/rawblob', size(blob_vol), 'Datatype', 'single');
h5write(fnameout, '/rawblob', single(blob_vol))
h5writeatt(fnameout, '/rawblob', 'bb', uint32(blob_bb))
h5write(fnameout, '/rawblob', single(blob_vol));
h5writeatt(fnameout, '/rawblob', 'bb', uint32(blob_bb));
% Mask comes from segmentation
h5create(fnameout, '/mask', vol_size, 'Datatype', 'uint8', 'Deflate', 1, 'ChunkSize', chunk_size);
if (~exist('blob_mask', 'var'))
h5write(fnameout, '/mask', ones(size(blob_vol), 'uint8'));
else
h5write(fnameout, '/mask', uint8(blob_mask));
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment