I am trying to display some local DICOM / .dcm files with XTK in the 2D render model that are LUNG CT IMAGES from the RIDER dataset hosted on the cancer imaging archive and there are no errors thrown by the console but the images are being outputted as blank. The files and the relative links to the files in the js are correct but still no output.
I also did the "Developer Heads Up" build: https://github.com/xtk/X/wiki/X:DevelopersHeadsUp,
as well as trying to use the nightly build: https://github.com/xtk/get/blob/gh-pages/xtk_nightly.js.
var _dicom = ['000008', '000009', '000010', '000011', '000012', '000013', '000014' , '000015' , '000016'];
var r = new X.renderer2D();
r.orientation = 'Z';
r.init();
var v = new X.volume();
v.file = _dicom.sort().map(function(v) {
return 'img/' + v + '.dcm';
});
r.add(v);
r.onWindowLevel();
r.render();
$('canvas').attr('id', 'xtkCanvas');
r.onShowtime = function() {
};
volume = v;
};
I have also verified that the DICOM files are uncompressed by using OsiriX...
Related
in my code I take image as input.
My user does not know much about technology , so they expect to give any image size they want , but I have limitations and I can't save larger images in my disc, so I want to compress images before saving them in my disc .
I appreciate helping me with this compression.
That's how i solved my problem using Magick.NET library :
i used the quality property to reduce the size and i did it in a loop , while the image size reaches my goal size :
MagickImage magickImge = new MagickImage(image);
int quality = magickImge.Quality;
long length = image.Length;
while (length > fileSizeInByte)
{
if (quality <= 6)
{
return Error;
}
quality = quality - ((quality * 15) / 100);
MagickImage lowQualityImage = new MagickImage(image);
lowQualityImage.Quality = quality;
byte[] newImageBytes = lowQualityImage.ToByteArray();
if (newImageBytes.Length <= fileSizeInByte)
{
magickImge.Quality = quality;
length = newImageBytes.Length;
}
}
i see that if the quality goes below 6 my pic will be illegible
I have a long array with data that I slice with Javascript in order to display data of different date ranges in my chart. This way the backend only needs to get the data once, and I can the just slice it on the client side.
// All data
var allLabels = [
// data here
];
var allData = [
// data here
];
Then I do:
var labelsCount = allLabels.length;
var dataCount = allData.length;
var updatedLabels;
var updatedData;
if($date_range === 'last_7_days')
{
updatedLabels = allLabels.slice(labelsCount - 7);
updatedData = allData.slice(labelsCount - 7);
}
if($date_range === 'last_30_days')
{
updatedLabels = allLabels.slice(labelsCount - 30);
updatedData = allData.slice(labelsCount - 30);
}
scoreChart.data.labels = updatedLabels;
scoreChart.data.datasets[0].data = updatedData;
scoreChart.update({
duration: 1000,
easing: 'easeInOutExpo'
});
This all works as expected. When switching from 30 to 7 days the points on the right of the 7 days disappear, and the graph scales and grows nicely to the new 7 days x-axis.
The other way around, when you have the graph of 7 days and then switch to 30, produces an ugly visual effect where the first point of the graph sticks to the side, overlaps the new data points and then animates.
After the animation the graph looks as expected, it's just the animation that's ugly. It's a little tricky to explain so hopefully the screenshots help. Green arrows indicate the animation direction. I've set the animation duration to 10s so I can take this screenshot, the red circle highlights the point that starts on the right of the graph and then animates to the left.
I've also tried adding this:
scoreChart.data.labels.pop();
scoreChart.data.datasets[0].data.pop();
scoreChart.update();
and this:
scoreChart.data.labels = [];
scoreChart.data.datasets[0].data = [];
scoreChart.update();
Before the line scoreChart.data.labels = updatedLabels; but that gives the same result.
Another thing I can do is only update the labels. The result is that the chart just zooms on the timeline when changing date ranges, without the nice animation as they have in the example.
You could try to first remove all labels and the data when switching to 'last_30_days'.
if($date_range === 'last_30_days')
{
scoreChart.data.labels = [];
scoreChart.data.datasets[0].data = [];
scoreChart.update({
duration: 500,
easing: 'easeInOutExpo'
});
updatedLabels = allLabels.slice(labelsCount - 30);
updatedData = allData.slice(labelsCount - 30);
}
I would like to save the drawn polygon in the code below to the postgis database :
Assume that mapbox is set correctly and that the polygon drawing and download works (i haven't put everything in the code to focus on the problem at hand)
<script type="text/javascript">
map.addControl(draw);
map.on('draw.create', updateArea);
map.on('draw.delete', updateArea);
map.on('draw.update', updateArea);
function updateArea(e) {
var data = draw.getAll();
var answer = document.getElementById('calculated-area');
if (data.features.length > 0) {
var area = turf.area(data);
// restrict to area to 2 decimal points
var rounded_area = Math.round(area*100)/100;
answer.innerHTML = '<p><strong>' + rounded_area + '</strong></p><p>square meters</p>';
var convertedData = 'text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data));
document.getElementById('export').setAttribute('href', 'data:' + convertedData);
document.getElementById('export').setAttribute('download','data.geojson');
} else {
answer.innerHTML = '';
if (e.type !== 'draw.delete') alert("Use the draw tools to draw a polygon!");
}
}
I'm trying to get the width and height of an image in a preprocess file.
I managed to generate the image with a style defined in the media/styles in the admin but I'm not able to render the width and/or height of the generated image (some will say I should just hardcode it in the twig file but I'm actually interested in learning how to get elements I'll need later :))
Here is what I'm using to get the image of a certain content type:
Let's assume my field's machine name is "field_image" and my content type is "article";
if (!empty($node->field_image->entity->getFileUri())) {
$style = ImageStyle::load('medium');
$image = $node->field_image->entity;
$variables['image'] = [
'src' => $style->buildUrl($image->getFileUri())
];
}
After that, all I need to do in node--article.html.twig is:
<img src="{{ image.src }}" />
But I also want to get the width and height attributes. How can I do that?
if ($node = \Drupal::routeMatch()->getParameter('node')) {
if ($node->hasField('field_image')) {
$imageField = $node->field_image;
$properties = $imageField->getProperties();
}
}
$properties will hold an array of the attributes your asking for.
$imageField is an instance of the Drupal\image\Plugin\Field\FieldType\ImageItem class. You can read the documentation here https://api.drupal.org/api/drupal/core%21modules%21image%21src%21Plugin%21Field%21FieldType%21ImageItem.php/class/ImageItem/8.2.x
This is the simplest solution I have found
if ($node = \Drupal::routeMatch()->getParameter('node')) {
if ($node->hasField('field_image')) {
//get first image on multi value field
$image = $node->field_image[0]->getValue();
$width = $image['width'];
$height = $image['height'];
}
}
we're working on a custom 3d engine (OpenGL) in which people can create, import and export custom 3d models, and we are using Assimp for our importing/exporting. At this point, importing works great, but when it comes to exporting, we are unable to save out any materials other than the default. While Assimp's website and others have loads of information on importing, there is little to no documentation on exporting. We managed to work out majority of the export process, but there doesn't seem to be any way of setting Assimp's aiMaterials' color values.
Assimp's documentation explains how to GET the color information from existing materials, ie..
*aiColor3D color (0.f,0.f,0.f);
mat->Get(AI_MATKEY_COLOR_DIFFUSE,color);*
http://assimp.sourceforge.net/lib_html/materials.html
but doesn't include anything on SETTING color information based on the model's material. (FYI, all of our models are flat colors; no textures). If anyone has any experience in exporting materials/colors, any help would be greatly appreciated. Here is what we have now..
//Create an Assimp node element to be a container object to hold all graphic information
scene.mRootNode = new aiNode();
scene.mMaterials = new aiMaterial*[ 1 ];
scene.mMaterials[ 0 ] = nullptr;
scene.mNumMaterials = 1;
mAllChildren.clear();
//Get ALL children on the scene (including down the hierarchy)
FindAllChildren(CScriptingUtils::GetDoc()->GetScene());
std::vector<std::weak_ptr<CNode>> children = mAllChildren;
int size = (int)children.size();
scene.mMaterials[ 0 ] = new aiMaterial();
scene.mRootNode->mMeshes = new unsigned int[ size ];
scene.mRootNode->mNumMeshes = size;
scene.mMeshes = new aiMesh*[ size ];
scene.mNumMeshes = size;
//Iterate through all children, retrieve their graphical information and push it into the Assimp structure
for(int i = 0; i < size; i++)
{
std::shared_ptr<CNode> childNode = children[i].lock();
scene.mRootNode->mMeshes[ i ] = i;
scene.mMeshes[ i ] = nullptr;
scene.mMeshes[ i ] = new aiMesh();
scene.mMeshes[ i ]->mMaterialIndex = 0;
aiMaterial* mat = scene.mMaterials[0];
And we need to do something like..
mat.color = childNode.color;
try that:
mat->AddProperty<aiColor3D>(color, 1, AI_MATKEY_COLOR_DIFFUSE);
It helps me. Also, I trying to export textures
newMat->AddProperty(matName, AI_MATKEY_NAME);
newMat->AddProperty(texturePath, AI_MATKEY_TEXTURE_DIFFUSE(0));
where 'matName' and 'texturePath' types are 'aiString'. What additiional parameters (besides path of texture) needed for correct displaying texture (because now textures not displayed, only color)?