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的更多相关文章

  1. Android系统Recovery工作原理之使用update.zip升级过程分析(一)

    通过分析update.zip包在具体Android系统升级的过程,来理解Android系统中Recovery模式服务的工作原理.我们先从update.zip包的制作开始,然后是Android系统的启动 ...

  2. Amazon API Gateway Importer整合过程小结

    (1)需要将swagger json转换成amazon api gateway 所需要的格式(根据Method Request中 Request PathsURL Query String Param ...

  3. 深入了解Libgdx中间Skin分类

    文不是直接翻译.. . 本文在Libgdx的官方wiki的基础上,加上一些自己的理解.所以,难免会一些甚至是非常多的理解非常片面的东西.写的不好,还请见谅.... 事实上 事实上.在LibGDX的官方 ...

  4. recovery 差分升级包制作超时

    我们在对android系统升级的时候,可以减少升级包的大小,只升级差异部分,也就是差分包升级,相关的描述可以参考:http://blog.csdn.net/csdn66_2016/article/de ...

  5. recovery 差分升级包制作超时【转】

    本文转载自:https://blog.csdn.net/csdn66_2016/article/details/73800349 我们在对android系统升级的时候,可以减少升级包的大小,只升级差异 ...

  6. centos 6.4安装杀毒软件clamAV 0.98[转]

    原文出处: http://dnuser.blog.51cto.com/4863891/1303829   1.查看系统版本 [root@local]# lsb_release -a LSB Versi ...

  7. Android系统Recovery工作原理之使用update.zip升级过程分析(一)---update.zip包的制作【转】

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7399822 这篇及以后的篇幅将通过分析update.zip包在具体Android系统升级的过 ...

随机推荐

  1. 使用STS4新建springboot项目

    1.配置maven,自定义setting文件和仓库,一定要用阿里云镜像地址下载依赖,官方太坑了,整了半天都没弄好,原来是下载太慢文件损坏 <mirror> <id>alimav ...

  2. LeetCode 599: 两个列表的最小索引总和 Minimum Index Sum of Two Lists

    题目: 假设 Andy 和 Doris 想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示. Suppose Andy and Doris want to cho ...

  3. 《细说PHP》第四版 样章 第二章 PHP的应用与发展 2

    2.2  PHP的应用 任何一种主流的编程语言,几乎都可以开发任何类型的软件.编程语言就是一种开发工具,而选择适合的工具去做适合的事儿,才能体现其应用价值.PHP最主要的应用,就是与数据库交互来开发W ...

  4. app自动化测试环境搭建之node+appium+ADT+MUMU模拟器

    一.安装Microsoft .NET Framework 4.5 检测本机已安装的程序中,是否已经安装Microsoft .NET Framework 4.5及以上的版本 如果没有安装,则获取安装文件 ...

  5. PVANET: Deep but Lightweight Neural Networks for Real-time Object Detection

    URL: https://arxiv.org/abs/1608.08021 year: 2016 TL;DR PVANet 一个轻量级多物体目标检测架构, 遵循 "less channels ...

  6. Distilling the Knowledge in a Neural Network

    url: https://arxiv.org/abs/1503.02531 year: NIPS 2014   简介 将大模型的泛化能力转移到小模型的一种显而易见的方法是使用由大模型产生的类概率作 ...

  7. 图解隐马尔可夫模型(HMM)

    写在前面 最近在写论文过程中,研究了一些关于概率统计的算法,也从网上收集了不少资料,在此整理一下与各位朋友分享. 隐马尔可夫模型,简称HMM(Hidden Markov Model), 是一种基于概率 ...

  8. javascript在数组的循环中删除元素

    在开发JavaScript应用的过程中,经常会遇到在循环中移除指定元素的需求. 按照常规的思路,就是对数组进行一个for循环,然后在循环里面进行if判断,在判断中删除掉指定元素即可. 但是实际情况往往 ...

  9. laravel使用Dingo\Api通过response()->json()返回空对象

    laravel使用Dingo\Api写接口跟android对接时,android一直反应解析错误,无法解析数据. { "status_code":200, "messag ...

  10. js使用工具将表单封装成json字符串传到后台,js截取字符串(学生笔记)

    <script src="js/jquery.min.js"></script> <script src="https://cdn.boot ...