getpatch
import time
import os
import math
import sys
import os,os.path,shutil
import numpy as np
import cv2 img_in_path = 'F:/project/Breast/InBreast/INBreast/removeother/'
# img_in_path = 'F:/project/Breast/InBreast/INBreast/imgtest/'
outpathimgyes = 'F:/project/Breast/InBreast/INBreast/outimgpatch/calcification/'
outpathimgno = 'F:/project/Breast/InBreast/INBreast/outimgpatch/no/'
txtPath = 'F:/project/Breast/InBreast/INBreast/AllTXTall/'
# txtPath = 'F:/project/Breast/InBreast/INBreast/ALLtest/'
outpathtxt = 'F:/project/Breast/InBreast/INBreast/outtxtpatch/'
txtType = 'txt'
txtLists = os.listdir(txtPath) #列出文件夹下所有的目录与文件 # Read all points into a list(before 21:30,715) for filename in txtLists:
pp = 0
ppp = 0
with open(txtPath + filename, 'r') as file:
print(filename)
lines = file.readlines()
dataset = [[] for i in range(len(lines))]
for i in range(len(dataset)):
dataset[i][:] = (item for item in lines[i].strip().split(',')) # 逐行读取数据
#print("dateset:", dataset)
# print(type(dataset[0][0]))
# print(dataset.__sizeof__())
u = np.array(dataset)
list = np.zeros((u.shape[0], 2))
for i in range(u.shape[0]):
# print(u[i,0][0])
findNumber = u[i,0].find(" ")
# print(findNumber)
list[i,0] = round(float(u[i, 0][0:findNumber]))
list[i,1] = round(float(u[i, 0][findNumber+1:])) # Read the same name image(before 21:30,715)
img = img_in_path + filename[:-4] + '.png' # out_path
img = cv2.imread(img)
black = np.zeros((img.shape[0], img.shape[1]))
for i in range(img.shape[0]):
for j in range(img.shape[1]):
if img[i,j][0] == 0 and img[i,j][1] == 0 and img[i,j][2] == 0:
black[i][j] = 1
print(img.shape[0],img.shape[1])
# Cutting distance has been determined, Handling cutting details(before 22.30, 715)
row = img.shape[0]/56;
col = img.shape[1]/56;
print(row,col) # 待考虑问题:黑色像素
for i in range(int(row-1)):
# print(i)
for j in range(int(col-1)):
tt = 0
pb = np.sum(black[i * 56:i * 56 + 112,j * 56:j * 56 + 112]) / 12544
# print("top_left:", i*56, j*56)
# print("bottom_right:",i*56+112,j*56+112)
for k in range(u.shape[0]):
if j*56<list[k,0]<j*56+112 and i*56<list[k,1]<i*56+112:
tt = tt + 1
patch_label = np.zeros((tt, 4))
tt1 = 0
for k in range(u.shape[0]):
if j*56<list[k,0]<j*56+112 and i*56<list[k,1]<i*56+112:
patch_label[tt1,0] = list[k,0] - j*56
patch_label[tt1,1] = list[k,1] - i*56
patch_label[tt1,2] = list[k,0]
patch_label[tt1,3] = list[k,1]
tt1 = tt1 + 1
if tt>0 and pb == 0:
patch = img[i * 56:i * 56 + 112,j * 56:j * 56 + 112]
pp = pp + 1
# print(patch.shape)
outputimg = outpathimgyes + '/' + filename[:-4] + '/' + filename[:-4] + '_'+ str(pp) + '.png'
cv2.imwrite(outputimg, patch)
outputtxt1 = outpathtxt + '/' + filename[:-4] + '/' + filename[:-4] + '_' + str(pp) + '.txt'
np.savetxt(outputtxt1, patch_label, fmt='%f')
if tt==0 and pb == 0:
patch = img[i * 56:i * 56 + 112,j * 56:j * 56 + 112]
ppp = ppp + 1
# print(patch.shape)
outputimg1 = outpathimgno + '/' + filename[:-4] + '/' + filename[:-4] + '_' + str(ppp) + '.png'
cv2.imwrite(outputimg1, patch) print(img.shape[0], img.shape[1])
print(pp,ppp) for i in range(int(row-1)):
tt = 0
pb = np.sum(black[i * 56:i * 56 + 112, img.shape[1] - 113:img.shape[1]-1]) / 12544
# print("top_right:",i*56,img.shape[1]-1)
# print("bottom_left:", i * 56+112, img.shape[1] - 113)
for k in range(u.shape[0]):
if img.shape[1] - 113 < list[k, 0] < img.shape[1]-1 and i * 56 < list[k, 1] < i * 56 + 112:
tt = tt + 1
patch_label = np.zeros((tt, 4))
tt1 = 0
# print(tt)
for k in range(u.shape[0]):
if img.shape[1] - 113 < list[k, 0] < img.shape[1]-1 and i * 56 < list[k, 1] < i * 56 + 112:
patch_label[tt1, 0] = list[k, 0] - j * 56
patch_label[tt1, 1] = list[k, 1] - i * 56
patch_label[tt1, 2] = list[k, 0]
patch_label[tt1, 3] = list[k, 1]
tt1 = tt1 + 1
if tt > 0 and pb == 0.1:
patch = img[i * 56:i * 56 + 112, img.shape[1] - 113:img.shape[1]-1]
pp = pp + 1
# print(patch.shape)
outputimg = outpathimgyes + '/' + filename[:-4] + '/' + filename[:-4] + '_' + str(pp) + '.png'
cv2.imwrite(outputimg, patch)
outputtxt1 = outpathtxt + '/' + filename[:-4] + '/' + filename[:-4] + '_' + str(pp) + '.txt'
np.savetxt(outputtxt1, patch_label, fmt='%f')
if tt == 0 and pb == 0:
patch = img[i * 56:i * 56 + 112, img.shape[1] - 113:img.shape[1]-1]
ppp = ppp + 1
# print(patch.shape)
outputimg1 = outpathimgno + '/' + filename[:-4] + '/' + filename[:-4] + '_' + str(ppp) + '.png'
cv2.imwrite(outputimg1, patch)
print(img.shape[0], img.shape[1])
#
#
#
for j in range(int(col-1)):
# print("bottom_left:", img.shape[0]-1, j*56)
# print("top_right:", img.shape[0] - 113, j * 56+112, )
tt = 0
pb = np.sum(black[img.shape[0]-113:img.shape[0] - 1, j * 56:j * 56+112]) / 12544
# print("top_right:",i*56,img.shape[1]-1)
# print("bottom_left:", i * 56+112, img.shape[1] - 113)
for k in range(u.shape[0]):
if j * 56 < list[k, 0] < j * 56+112 and img.shape[0]-113 < list[k, 1] < img.shape[0]-1:
tt = tt + 1
patch_label = np.zeros((tt, 4))
tt1 = 0
# print(tt)
for k in range(u.shape[0]):
if j * 56 < list[k, 0] < j * 56+112 and img.shape[0]-113 < list[k, 1] < img.shape[0]-1:
patch_label[tt1, 0] = list[k, 0] - j * 56
patch_label[tt1, 1] = list[k, 1] - i * 56
patch_label[tt1, 2] = list[k, 0]
patch_label[tt1, 3] = list[k, 1]
tt1 = tt1 + 1
if tt > 0 and pb == 0:
patch = img[img.shape[0]-113:img.shape[0] - 1, j * 56:j * 56+112]
pp = pp + 1
# print(patch.shape)
outputimg = outpathimgyes + '/' + filename[:-4] + '/' + filename[:-4] + '_' + str(pp) + '.png'
cv2.imwrite(outputimg, patch)
outputtxt1 = outpathtxt + '/' + filename[:-4] + '/' + filename[:-4] + '_' + str(pp) + '.txt'
np.savetxt(outputtxt1, patch_label, fmt='%f')
if tt == 0 and pb == 0:
patch = img[img.shape[0]-113:img.shape[0] - 1, j * 56:j * 56+112]
ppp = ppp + 1
# print(patch.shape)
outputimg1 = outpathimgno + '/' + filename[:-4] + '/' + filename[:-4] + '_' + str(ppp) + '.png'
cv2.imwrite(outputimg1, patch)
# print(img.shape[0], img.shape[1]) # A = np.array([[1, 2], [3, 4], [5, 6]])
# print(np.sum(A))
print(pp)
getpatch的更多相关文章
- Android系统Recovery工作原理之使用update.zip升级过程分析(一)
通过分析update.zip包在具体Android系统升级的过程,来理解Android系统中Recovery模式服务的工作原理.我们先从update.zip包的制作开始,然后是Android系统的启动 ...
- Amazon API Gateway Importer整合过程小结
(1)需要将swagger json转换成amazon api gateway 所需要的格式(根据Method Request中 Request PathsURL Query String Param ...
- 深入了解Libgdx中间Skin分类
文不是直接翻译.. . 本文在Libgdx的官方wiki的基础上,加上一些自己的理解.所以,难免会一些甚至是非常多的理解非常片面的东西.写的不好,还请见谅.... 事实上 事实上.在LibGDX的官方 ...
- recovery 差分升级包制作超时
我们在对android系统升级的时候,可以减少升级包的大小,只升级差异部分,也就是差分包升级,相关的描述可以参考:http://blog.csdn.net/csdn66_2016/article/de ...
- recovery 差分升级包制作超时【转】
本文转载自:https://blog.csdn.net/csdn66_2016/article/details/73800349 我们在对android系统升级的时候,可以减少升级包的大小,只升级差异 ...
- centos 6.4安装杀毒软件clamAV 0.98[转]
原文出处: http://dnuser.blog.51cto.com/4863891/1303829 1.查看系统版本 [root@local]# lsb_release -a LSB Versi ...
- Android系统Recovery工作原理之使用update.zip升级过程分析(一)---update.zip包的制作【转】
本文转载自:http://blog.csdn.net/mu0206mu/article/details/7399822 这篇及以后的篇幅将通过分析update.zip包在具体Android系统升级的过 ...
随机推荐
- NXP_RTCESL库
恩智浦实时控制嵌入式软件库(缩写为RTCESL,以前为恩智浦嵌入式软件库FSLESL)是一组算法,从基础数学运算到高级数学变换以及高级观测器,这些都可以方便地用在复杂的实时控制应用中以及我们的电机控制 ...
- Ubuntu 18.04 安装 python 的 redis 库
安装 如果只是安装了 python2.x 或者 python3.x,直接安装即可,命令如下: pip install redis 如果是同时安装了 python2.x 和 python3.x 的,则需 ...
- 201871010116-祁英红《面向对象程序设计(java)》第十三周学习总结
博文正文开头格式:(2分) 项目 内容 <面向对象程序设计(java)> https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://ww ...
- 趣谈Linux操作系统学习笔记:第二十四讲
一.小内存的分配基础 1.kmem_cache_alloc_node的作用 通过这段代码可以看出,它调用了kmem_cache_alloc_node函数,在task_struct的缓存区域task_s ...
- npm ERR! code ENOLOCAL
Microsoft Windows [版本 ] 版权所有 (c) Microsoft Corporation.保留所有权利. G:\vue>cnpm i vue-router -S 'cnpm' ...
- golang--连接redis数据库并进行增删查改
(1)安装第三方开源的redis库: (2)在使用redis之前,需要安装第三方库,在GOPATH路径下执行安装指令--$GOPATH$:go get github.com/garyburd/redi ...
- Linux 小工具
1. 截图工具 shutter 安装 sudo add-apt-repository ppa:shutter/ppa sudo apt-get update sudo apt-get install ...
- Android Monkey的用法(一)
Monkey 简介 ü Monkey 是一个命令行工具,可以运行在 Android 模拟器里或真实设备中.它可以向系统发送伪随机(pseudo-random)的用户事件流(如按键输入.触摸屏输入 ...
- python 学习(day1)
初识python python的创始人为吉多*范罗苏姆(Guido van Rossum).1989年圣诞节期间,开发出来的脚本解释程序. python是⼀⻔什么样的语言 python 是一门解释型语 ...
- dell服务器已有阵列新增的磁盘无法识别显示外来
问题描述: 今天遇到个插入新硬盘显示外来盘,然后不可用,然后电话问了一下戴尔的工程师 说需要清除一下原来磁盘的阵列信息之类的,才能识别到,这里就做一个笔记记录一下,顺便分享给有需要的朋友! 解决方法: ...