简体   繁体   English

如何在 python 的单个列表中制作每个强度值的像素?

[英]How can I make the pixels of each intensity value in an individual list in python?

I need to make the pixels with the same intensity value in a list so I will get a list of lists of intensity values and each list has the pixels with the same intensity value.我需要在列表中制作具有相同强度值的像素,因此我将获得强度值列表的列表,并且每个列表都有具有相同强度值的像素。

import nibabel as nib
import numpy as np 
from PIL import Image
import seaborn as sns
import matplotlib.pyplot as plt
from numpy import asarray
from scipy import ndimage, misc, stats
import cv2


### Load the image 

img  = nib.load('input_dir/FLAIR1.nii.gz')
img_data = img.get_fdata()
imgs = img_data[:, :, 23]

rows, col = imgs.shape
my_nlist = [[] for k in range(y.shape[0])]
print(im_arr[2,2])
for i in range(0, rows):
    for j in range(0, col): 
        pixel = imgs[i, j]
        for k in range(y.shape[0]):
            if pixel == [k]:               
                my_nlist[k].append(pixel) 

Don't make it harder on yourself than you have to:) this is exactly what a histogram is meant for!不要让自己变得更难:)这正是直方图的意义所在!

import matplotlib.pyplot as plt
import cv2 as cv # You won't be needing cv2, it is just needed to create this example

img = cv.imread('dir/to/img', 0) # notice the grayscale flag
hist, bins, _ = plt.hist(img) # hist contains the list of pixels with the same intensity for each intensity in the picture
plt.show() # in case you want to visualize it

This is what it will look like:这就是它的样子:

例子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何循环浏览图像中的单个像素并输出每行的最高RGB值像素? - How can I cycle through individual pixels in an image and output the highest RGB valued pixel of each row? 我有一个矩阵,其中每个元素都是 label 和一个值。 我该如何表示它,以便 label 给出颜色和强度值? - I have a matrix in which each element is a label and a value. How can I represent it so that the label gives the color and the value the intensity? Python:如何计算字母表中每个单独字符的数量 - Python: How can I count the number of each individual character of the alphabet 如何在pygame中有效地绘制单个像素? - How to make drawing individual pixels efficient in pygame? 如何将列表传递给 python 中的 CSV 编写器并使其在单个单元格中写入每个元素 - How to pass a list to a CSV writer in python and make it write each element in individual cells 对于 python 我想让列表中的每个值响应另一个值 - For python I want to make each values in a list respond to another value python dicts列表-将每个键值转换为单独的dict - python list of dicts - convert each key-value as a individual dict 如何在不缩短python中的列表的情况下打印列表中的每个值? - How can I print each value in a list without shortening the list in python? 如何在各行上打印列表的每个元素,在python中以行号开头? - How do I print each element of a list on individual lines, preceded by the line number in python? 如何均衡一组图像的强度? - How can I equalise intensity for a set of images?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM