\nhttp:\/\/radiology-technologist.info\/2020\/01\/28\/post-417\/\n<\/div><\/figure>\n\n\n\n
.rfind(“\/”)<\/p>\n\n\n\n
\u3067\u6700\u5f8c\u304b\u3089\u6570\u3048\u3066 “\/” \u304c\u4f55\u6587\u5b57\u76ee\u306b\u3042\u308b\u304b\u3092\u8abf\u3079\u307e\u3059\u3002<\/p>\n\n\n\n
\u305d\u3057\u3066\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\u304b\u3089\u3001\u305d\u306e\u6587\u5b57\u5206\u3060\u3051\u5207\u308a\u629c\u3044\u3066\u3042\u3052\u3001\u5148\u307b\u3069\u9078\u629e\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u306e\u5f8c\u308d\u306b\u3064\u3051\u3066\u3042\u3052\u308c\u3070\u3044\u3044\u308f\u3051\u3067\u3059\u3002<\/p>\n\n\n\n
\u5909\u6570cou\u3068\u3057\u3066\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u524d\u306b\u3042\u308b”\/”\u307e\u3067\u306e\u6587\u5b57\u6570\u3092\u5165\u308c\u307e\u3059\u3002<\/p>\n\n\n\n
cou = filenames[i].rfind(“\/”)<\/p>\n\n\n\n
\uff08\u306a\u304a\u3001[i]\u306f\u5f8c\u3067for\u6587\u306e\u4e2d\u3067\u3053\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u3046\u306e\u3067\u5165\u308c\u3066\u3044\u307e\u3059\u3002\uff09<\/p>\n\n\n\n
\u305d\u306e\u6570\u5b57\u6587\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\u304b\u3089\u629c\u304d\u51fa\u305b\u3070\u3044\u3044\u306e\u3067<\/p>\n\n\n\n
filenames[i][cou:]<\/p>\n\n\n\n
\u3053\u308c\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u629c\u304d\u51fa\u3057\u304c\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n\n\n\n
<\/p>\n\n\n\n
\u753b\u50cf\u5f62\u5f0f\u306f\u4f55\u306b\u3059\u308b\u304b\uff1f<\/h3>\n\n\n\n
\u753b\u50cf\u5f62\u5f0f\u306f\u3001jpg,png,bmp,tiff\u3069\u306e\u5f62\u5f0f\u306b\u3059\u308b\u304b\u6c7a\u307e\u3063\u305f\u3089\u3001\u4fdd\u5b58\u3059\u308b\u6642\u3001\u30d1\u30b9\u306e\u6700\u5f8c\u306b\u4ed8\u3051\u3066\u3042\u3052\u308c\u3070\u3044\u3044\u3060\u3051\u3067\u3059\u3002<\/p>\n\n\n\n
\u306a\u306e\u3067<\/p>\n\n\n\n
“.jpg” “.png” “.bmp” “.tiff”<\/p>\n\n\n\n
\u3053\u308c\u3060\u3051\u3067\u3001\u753b\u50cf\u5f62\u5f0f\u306e\u6307\u5b9a\u304c\u7d42\u308f\u308a\u3067\u3059\u3002<\/p>\n\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
\u753b\u50cf\u4fdd\u5b58<\/h3>\n\n\n\n
\u6b21\u306f\u3001\u753b\u50cf\u3092\u4fdd\u5b58\u3057\u3066\u3044\u304f\u5de5\u7a0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n
cv2.imwrite(\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9,\u30c7\u30fc\u30bf)<\/p>\n\n\n\n
\u306e\u30b3\u30fc\u30c9\u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n
\u307e\u305a\u306f\u4fdd\u5b58\u5148\u306e\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n
\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\u306f\u3001\u753b\u50cf\u4fdd\u5b58\u306e\u30d5\u30a9\u30eb\u30c0\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3001\u62e1\u5f35\u5b50\u3092\u4ed8\u3051\u3066\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n
\u4fdd\u5b58\u30d5\u30a9\u30eb\u30c0\u306ffol\u306e\u5909\u6570\u540d\u3067\u53d6\u5f97\u3057\u307e\u3057\u305f\u306d\u3002<\/p>\n\n\n\n
\u6b21\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u306f<\/p>\n\n\n\n
cou = filenames[i].rfind(“\/”)<\/p>\n\n\n\n
filenames[i][cou:]<\/p>\n\n\n\n
\u306e2\u6587\u3067\u629c\u304d\u51fa\u3057\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n
\u753b\u50cf\u5f62\u5f0f\u306fjpeg\u3068\u3057\u307e\u3059\u3068”.jpg”\u3068\u306a\u308a\u307e\u3059\u306e\u3067<\/p>\n\n\n\n
\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9fname\u306f<\/p>\n\n\n\n
fname = fol + filenames[i][cou:] + “.jpg”<\/p>\n\n\n\n
\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n
\u753b\u50cf\u30c7\u30fc\u30bf\u306fdcm_copy\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n
<\/p>\n\n\n\n
\u5f8c\u306ffor\u6587\u306e\u4e2d\u306b\u4e0a\u306e\u30b3\u30fc\u30c9\u3092\u5165\u308c\u3066\u3042\u3052\u308c\u3070\u3044\u3044\u306e\u3067\u3001\u30de\u30a6\u30b9\u30a4\u30d9\u30f3\u30c8\u306e\u6587\u3082\u5408\u308f\u305b\u308b\u3068<\/p>\n\n\n\n
\nif event == cv2.EVENT_RBUTTONDOWN:\n\tfol = fs.folder()\n\n\tfor i in range(len(dcm_copy)):\n\n\t\tcou = filenames[i].rfind(\"\/\")\n\t\tfname = fol + filenames[i][cou:] + \".jpg\"\n\n\t\tcv2.imwrite(fname,dcm_copy[i])\n<\/code><\/pre>\n\n\n\n\u3053\u308c\u3067\u30b3\u30fc\u30c9\u306f\u5b8c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n
<\/p>\n\n\n\n
\u305f\u3060\u3001\u3053\u3053\u3067\u554f\u984c\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n
\u4eca\u4f5c\u6210\u3057\u3066\u3044\u308b\u30b3\u30fc\u30c9\u306f\u30de\u30a6\u30b9\u30a4\u30d9\u30f3\u30c8\u306e\u95a2\u6570\u5185\u3067\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u95a2\u6570\u5916\u3067\u5ba3\u8a00\u3057\u3066\u3044\u308bfilenames\u304a\u3088\u3073\u3001\u753b\u50cf\u8868\u793a\u306b\u4f5c\u6210\u3057\u305f\u914d\u5217dcm_copy\u306f\u4f7f\u7528\u3067\u304d\u307e\u305b\u3093\u3002\u306a\u306e\u3067\u3053\u308c\u3092\u4f7f\u3046\u306b\u306fglobal\u3067\u5ba3\u8a00\u3057\u3066\u304a\u304b\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002\u306a\u306e\u3067\u3001\u30de\u30a6\u30b9\u30a4\u30d9\u30f3\u30c8\u306e\u95a2\u6570\u3092\u5ba3\u8a00\u3057\u305f\u76f4\u4e0b\u306b\u5ba3\u8a00\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002\u524d\u56de\u306e\u30b3\u30fc\u30c9\u3067g\u3068\u3044\u3046\u5909\u6570\u3092\u5ba3\u8a00\u3057\u305f\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u305d\u306e\u5f8c\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n
<\/p>\n\n\n\n
def onMouse(event, x, y, flag, params):
global g,dcm_copy,filenames<\/p>\n\n\n\n
\u3053\u308c\u3067\u3001\u95a2\u6570\u5916\u3067\u5ba3\u8a00\u3057\u3066\u3044\u305ffilenames\u304a\u3088\u3073\u3001dcm_copy\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
\u5b8c\u6210\u3057\u305f\u30b3\u30fc\u30c9<\/h2>\n\n\n\n\n# coding: UTF-8\nimport fileselect as fs #\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\u53d6\u5f97\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\nimport numpy as np\nimport pydicom\nimport math\nimport copy\nimport cv2\n\ndef onMouse(event, x, y, flag, params):\n global g,dcm_copy,filenames\n g = params\n\n if event == cv2.EVENT_MOUSEWHEEL:\n if flag > 0:\n g -= 1\n elif flag < 0:\n g += 1\n\n if g <= 0:\n g = 0\n elif g >= len(filenames)-1:\n g = len(filenames)-1\n\n if event == cv2.EVENT_RBUTTONDOWN:\n fol = fs.folder()\n\n for i in range(len(dcm_copy)):\n\n cou = filenames[i].rfind(\"\/\")\n fname = fol + filenames[i][cou:] + \".jpg\"\n\n cv2.imwrite(fname,dcm_copy[i])\n\ndef make_LUT(val):\n global lookup_tbl, dcm_copy\n wl = cv2.getTrackbarPos('WL', 'dcm_image')\n ww = cv2.getTrackbarPos('WW', 'dcm_image')\n\n ww_low = wl - ww \/\/ 2\n ww_high = wl + ww \/\/ 2\n lookup_tbl[0:ww_low] = 0\n lookup_tbl[ww_high:maxvalue] = 255\n for i in range(ww_low, ww_high, 1):\n lookup_tbl[i] = math.ceil((i - ww_low) * (256 \/ (ww_high - ww_low)))\n\n dcm_copy = lookup_tbl[dcm_main]\n\n dcm_copy =cv2.convertScaleAbs(dcm_copy, alpha=255\/dcm_copy.max())\n\nfilenames = fs.multi_files()\n\ndcm = pydicom.dcmread(filenames[0])\nrow,columns = dcm.pixel_array.shape[0],dcm.pixel_array.shape[1]\n\ndcm_copy = np.zeros((len(filenames), row, columns),dtype = 'int16')\n\nfor i in range(len(filenames)):\n dcm = pydicom.dcmread(filenames[i])\n dcm_arr = dcm.pixel_array\n dcm_copy[i] = dcm_arr\n\ndcm_main = copy.deepcopy(dcm_copy)\n\ncv2.namedWindow('dcm_image',cv2.WINDOW_NORMAL)\n\nmaxvalue = dcm_copy.max()\nlookup_tbl = np.zeros(maxvalue+1, dtype='int16')\n\ncv2.createTrackbar(\"WL\", \"dcm_image\", (maxvalue \/\/ 2), maxvalue, make_LUT)\ncv2.createTrackbar(\"WW\", \"dcm_image\", (maxvalue \/\/ 4), maxvalue, make_LUT)\n\nmake_LUT(0)\ng = 0\n\nwhile 1:\n params = g\n cv2.setMouseCallback('dcm_image', onMouse, params)\n cv2.imshow('dcm_image', dcm_copy[g])\n\n k = cv2.waitKey(1)\n if k == ord('q'):\n break\n\n<\/code><\/pre>\n\n\n\n\u3068\u306a\u308a\u307e\u3059\u3002\u3044\u304b\u304c\u3067\u3057\u305f\u304b\uff1f<\/p>\n\n\n\n
\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\u3002<\/p>\n\n\n\n
<\/p>\n\n\n\n
\u74b0\u5883<\/h2>\n\n\n\n- windows10<\/li>
- python3.6.1 <\/li>
- Anaconda custom(64-bit)<\/li>
- PyCharm2020.2(Communication Edition)<\/li><\/ul>\n\n\n\n
<\/p>\n","protected":false},"excerpt":{"rendered":"
\u524d\u56de\u3001OpenCV\u3092\u7528\u3044\u3066\u30de\u30a6\u30b9\u30db\u30a4\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u753b […]<\/p>\n","protected":false},"author":1,"featured_media":363,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,4],"tags":[9,56,45,57,7,58],"class_list":["post-413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencv","category-python","tag-dicom","tag-jpeg","tag-opencv","tag-png","tag-python","tag-tiff"],"aioseo_notices":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/radiology-technologist.info\/wp-content\/uploads\/2019\/11\/python_logo.png?fit=614%2C612","_links":{"self":[{"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/posts\/413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/comments?post=413"}],"version-history":[{"count":18,"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":581,"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/posts\/413\/revisions\/581"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/media\/363"}],"wp:attachment":[{"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/radiology-technologist.info\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}