Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmasoud1 committed Mar 27, 2024
1 parent e985526 commit 773756a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions js/brainchop/mainMeshNetFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ rgbToHex = (rgbObj) => {


/**
* Get MRI after threshold noisy voxels around the brain for better cropping later
* Get MRI mask after threshold noisy voxels around the brain for better cropping later
* @since 3.0.0
* @param {tf.Tensor} tensor - Tensor3d, e.g. Tensor3d of all MRI volume data
* @param {number} percentage - Threshold percentage is just a number between 0 and 1
Expand All @@ -1278,18 +1278,18 @@ applyMriThreshold = async(tensor, percentage) => {
thresholdTensor.dispose();

// Use tf.tidy for synchronous operations
const denoisedMriData = tf.tidy(() => {
return tf.tidy(() => {
const dataForProcessing = tensor.clone();

// Thresholding (assuming background has very low values compared to the head)
const mask = dataForProcessing.greater(threshold[0]);
const denoisedMriData = dataForProcessing.mul(mask);
//-- const denoisedMriData = dataForProcessing.mul(mask);

// No need to manually dispose dataForProcessing and mask, as tf.tidy() will dispose them auto.
return denoisedMriData;
return mask;
});

return denoisedMriData;
//-- return denoisedMriData;
}


Expand Down Expand Up @@ -4876,13 +4876,12 @@ function convByOutputChannelAndInputSlicing(input, filter, biases, stride, pad,
if( (autoThresholdValue > 0) && (autoThresholdValue <= 1) ) {

// Filtered MRI from noisy voxel below autoThresholdValue
slices_3d = await applyMriThreshold(slices_3d, autoThresholdValue);
mask_3d = await applyMriThreshold(slices_3d, autoThresholdValue);
} else {
console.log("No valid crop threshold value");
}

// binarize original image
mask_3d = slices_3d.greater([0]).asType('bool');
// binarize original image
mask_3d = slices_3d.greater([0]).asType('bool');
}

} else {

Expand Down Expand Up @@ -6115,13 +6114,12 @@ get3dObjectBoundingVolume = async(slices_3d) => {
if( (autoThresholdValue > 0) && (autoThresholdValue <= 1) ) {

// Filtered MRI from noisy voxel below autoThresholdValue
slices_3d = await applyMriThreshold(slices_3d, autoThresholdValue);
mask_3d = await applyMriThreshold(slices_3d, autoThresholdValue);
} else {
console.log("No valid crop threshold value");
}

// binarize original image
mask_3d = slices_3d.greater([0]).asType('bool');
// binarize original image
mask_3d = slices_3d.greater([0]).asType('bool');
}

} else {

Expand Down Expand Up @@ -6169,8 +6167,12 @@ get3dObjectBoundingVolume = async(slices_3d) => {

//-- Reference voxel that cropped volume started slice with it
let refVoxel = [row_min, col_min, depth_min];
console.log("refVoxel :", refVoxel)

// -- Starting form refVoxel, size of bounding volume
let boundVolSizeArr = [row_max - row_min + 1, col_max - col_min + 1, depth_max - depth_min + 1];
let boundVolSizeArr = [row_max - row_min + 1, col_max - col_min + 1, depth_max - depth_min + 1];

console.log("boundVolSizeArr :", boundVolSizeArr)

coords.dispose();

Expand Down Expand Up @@ -6622,7 +6624,7 @@ checkInferenceModelList = () => {

preModel_slices_3d = preModel_slices_3d.transpose();
console.log("Input transposed for pre-model");

} else {
console.log("Transpose not enabled for pre-model");
}
Expand Down
2 changes: 1 addition & 1 deletion js/brainchop/mainParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
enableTranspose : true, // Keras and tfjs input orientation may need a tranposing step to be matched
enableCrop: true, // For speed-up inference, crop brain from background before feeding to inference model to lower memory use.
cropPadding: 2, // Padding size add to cropped brain
autoThreshold: 0.2, // Threshold between 0 and 1, given no preModel and tensor is normalized either min-max or by quantiles. Will remove noisy voxels around brain
autoThreshold: 0.1, // Threshold between 0 and 1, given no preModel and tensor is normalized either min-max or by quantiles. Will remove noisy voxels around brain
enableQuantileNorm: false, // Some models needs Quantile Normaliztion.
filterOutWithPreMask: false, // Can be used to multiply final output with premodel output mask to crean noisy areas
enableSeqConv: false, // For low memory system and low configuration, enable sequential convolution instead of last layer
Expand Down

0 comments on commit 773756a

Please sign in to comment.