【前端】【cornerstone】【未完善】cornerstone重新加载图像尝试——拒绝花里胡哨

  • 问题
  • 正常加载图像
  • 尝试方法
    • 方法1【无效】:直接修改columnPixelSpacing、rowPixelSpacing
    • 方法2【无效】:生成新的viewport
    • 方法3【有效】:还是采用加载图像的老办法用loadimage重新加载一遍

cornerstone源码:
cornerstone/src/reset.js
cornerstone/src/internal/getDefaultViewport.js
cornerstone/src/getDefaultViewportForImage.js
cornerstone/src/displayImage.js

问题

问题:重新加载element承载的图像时可能直接加载出来图像大小/位置就不对,或采用cornerstone.reset(element);重置视图时大小、位置会发生偏差。

正常加载图像

注册element

const element = document.getElementById('dicomimage');
cornerstone.enable(element);
this.img_show_element = element;
this.img_show_element.tabIndex = 0;
this.img_show_element.focus();

加载图像

imageId = ...cornerstone.loadImage(imageId).then(function(image) {that.imageHeight = image.height;that.imageWidth = image.width;// 若需要对图像进行处理imgData = ...function loadPixelData () {return imgData;}// 这些参数都是需要调试的var modified_image = {imageId: imgIdItem, // XXX: 注意这个imageId很重要,没有的话注册的组件所对应的element的imageId只能为undefinedminPixelValue : 0,maxPixelValue : 255,slope: 1.0,intercept: 0,windowCenter : 127,windowWidth : 256,getPixelData: loadPixelData,rows: that.imageHeight,columns: that.imageWidth,height: that.imageHeight,width: that.imageWidth,color: true,rgba: true,columnPixelSpacing: .8984375,rowPixelSpacing: .8984375,sizeInBytes: that.imageWidth * that.imageHeight * 4};var viewport = cornerstone.getDefaultViewportForImage(that.img_show_element, image);cornerstone.displayImage(that.img_show_element, modified_image, viewport);// 若不进行处理直接加载image即可(把上面的modified_image换成image)
});

尝试方法

方法1【无效】:直接修改columnPixelSpacing、rowPixelSpacing


that.img_show_element = ...
modified_image = ...const cornerstone_canvas = that.img_show_element
that.cornerstone_show_height = cornerstone_canvas.offsetHeight//getAttribute('height')
that.cornerstone_show_width = cornerstone_canvas.offsetWidth//getAttribute('width')
if(modified_image.width / modified_image.height >= that.cornerstone_show_width / that.cornerstone_show_height){modified_image.columnPixelSpacing = modified_image.rowPixelSpacing = that.cornerstone_show_width / modified_image.width;
}else{modified_image.columnPixelSpacing = modified_image.rowPixelSpacing = that.cornerstone_show_height / modified_image.height;let viewPortOpion = cornerstone.getViewport(that.img_show_element)
viewPortOpion.scale = modified_image.columnPixelSpacing;
viewPortOpion.displayedArea.tlhc.x = 1;
viewPortOpion.displayedArea.tlhc.y = 1;
viewPortOpion.displayedArea.brhc.x = modified_image.width;
viewPortOpion.displayedArea.brhc.y = modified_image.height;
// TODO:该项设置后仍然不好使,那不知道displayedArea.rowPixelSpacing是干啥的
viewPortOpion.displayedArea.rowPixelSpacing = modified_image.rowPixelSpacing;
viewPortOpion.displayedArea.columnPixelSpacing = modified_image.columnPixelSpacing;
cornerstone.setViewport(that.img_show_element, viewPortOpion);
cornerstone.displayImage(that.img_show_element, modified_image, viewPortOpion);
}

方法2【无效】:生成新的viewport

that.img_show_element = ...
modified_image = ...var viewport = cornerstone.getDefaultViewportForImage(that.img_show_element, modified_image);
cornerstone.displayImage(that.img_show_element, modified_image, that.viewport);

方法3【有效】:还是采用加载图像的老办法用loadimage重新加载一遍

也就是虽然原有的that.img_show_element也包含canvas,但是不要想着用已有的canvas
可以通过cornerstone.getEnabledElement查看一下:

console.log('loadImageData.this.img_show_element', cornerstone.getEnabledElement(that.img_show_element))
var enableElement = cornerstone.getEnabledElement(that.img_show_element);
// 这实际上就应该是开头说的cornerstone.reset()的调用效果,具体可以看一开始给出的源代码链接。调了很多次都不对,不过可能是能调出来的
var reset_viewport = cornerstone.getDefaultViewportForImage(that.img_show_element, enableElement.image);
console.log('loadImageData->reset_viewport', reset_viewport);

【前端】【cornerstone】【未完善】cornerstone重新加载图像大小问题——拒绝花里胡哨相关推荐

  1. 解密 | OpenCV加载图像大小是有限制的 ?

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 问题来由 最近有人问一个问题,就是它有个大小800MB的图像文件, ...

  2. 【js】【cornerstone】cornerstone使用url方式加载图像

    [js][cornerstone]cornerstone使用url方式加载图像 引入cornerstoneWebImageLoader loadImage 引入cornerstoneWebImageL ...

  3. 前端性能优化学习 08 资源加载优化

    图片延迟加载 什么是延迟加载 首先来想象一个场景,当浏览一个内容丰富的网站时,比如电商的商品列表页.主流视频网站的节目列表等,由于屏幕尺寸的限制,每次只能查看到视窗中的那部分内容,而要浏览完页面所包含 ...

  4. 前端性能优化——如何提高页面加载速度?

    1.将样式表放在头部 首先说明一下,将样式表放在头部对于实际页面加载的时间并不能造成太大影响,但是这会减少页面首屏出现的时间,使页面内容逐步呈现,改善用户体验,防止"白屏". 我们 ...

  5. 前端性能优化:使用媒体查询加载指定大小的背景图片

    日期:2013-7-8  来源:GBin1.com 直到CSS @supports被广泛支持,CSS媒体查询的使用接近于CSS中写逻辑控制.我们经常用CSS媒体查询来根据设备调整CSS属性(通常根据屏 ...

  6. 在HBuilder创建前端web项目时,图片加载不出来,怎么解决?

    在HBuilder创建前端web项目时,图片加载不出来,如下: 解决方法: 将图片文件路径减少,可正常显示,如图:

  7. 前端如何解决图片太多加载资源慢的问题

    前端如何解决图片太多加载资源慢的问题 使用图片服务器 使用图片懒加载 CSS sprites 使用图片服务器 把图片服务器与应用服务器分开,图片服务器采用独立域名 ,css.js和图片就可以并发请求了 ...

  8. User Profile Service服务未登录,无法加载用户配置文件的解决方案

    最近驱动人生用户反映win10开机提示User Profile Service服务未登录,无法加载用户配置文件.造成这个问题的原因通常是用户配置文件.文件夹被删除或用户配置文件损坏及用户已停止或禁用此 ...

  9. 用jQuery预加载图像

    我正在寻找一种快速简单的方法来用JavaScript预加载图像. 如果重要的话,我正在使用jQuery. 我在这里( http://nettuts.com ... )看到了: function com ...

最新文章

  1. linux i2c ioctl错误,关于读写I2C总线的时候出错的有关问题
  2. [cocos2d-x]游戏开发系列教程-搭建cocos2d-x的windows开发环境
  3. 072_Math对象
  4. 在看完《Programming in Lua》之后
  5. 【实施工程师之家】——mysql四种索引PRIMARY(主键索引)、INDEX(一般索引)、UNIQUE(非空索引)、FULLTEXT(全文索引)应用
  6. 无悔入华夏怎么一直显示服务器,无悔入华夏完整版
  7. android studio gradle 打出jar,同时将依赖的第三方jar打包在一起
  8. SAP Commerce Cloud启动时遇到的9001端口被占用的问题
  9. 计算机史上首篇教你从算法问题提炼算法思想的文章
  10. 一切事物皆对象_基础篇
  11. pycharm 操作的一些设置,记录下
  12. 6.5版本虚拟机的封装
  13. “通用大模型”趋势下,AI未来当如何?
  14. 税务系统什么时候使用计算机,2020年税务师考试题量、答题要求及计算器使用规定...
  15. 近期你已经授权登录过_不查不知道,我的微信、QQ 居然授权登录过这么多应用!...
  16. MAC 升级monterey 系统后无法启动Parallels Desktop
  17. ubuntu18.04 network有线网络图标缺失解决记录
  18. Hbuilder-应用程序打包
  19. 任正非:为什么华为选择与西工大合作,腾讯T4架构师
  20. pytorch embedding层详解(从原理到实战)

热门文章

  1. RxJava使用Observable.zip的Iterable参数
  2. php多进程采集百度,php实现多进程下载百度网盘文件
  3. java web ssh jar_java web 汽车美容管理系统 ssh 毕设作品
  4. python怎么判断字段不存在_Python 判断一个对象是否存在
  5. java 返回值给c_Java有陷阱,用时需谨慎——慎用入参做返回值
  6. 洛谷P3152 正整数序列
  7. 操作系统 第一章 计算机系统概述
  8. 计算机算法设计与分析 旅行售货员问题
  9. 词汇表生成(C语言)
  10. Python装饰器几个有用又好玩的例子