# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import cv2
img = cv2.imread('out3.png',0)
hsv_im=cv2.CASCADE_SCALE_IMAGE(img)
#hsv_im = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

from PIL import Image
im = Image.open('output.png')
for pixel in im.getdata():
    if pixel == (128,0,0):
        print ("Red coloured pixel")
    else:
        pixel = [0, 0, 0]


# +
from PIL import Image

imagePath = 'output.png'
newImagePath = 'out4.png'
im = Image.open(imagePath)

def redOrBlack (im):
    newimdata = []
    redcolor = (255,0,0)
    blackcolor = (0,0,0)
    for color in im.getdata():
        if color == redcolor:
            newimdata.append( redcolor )
        else:
            newimdata.append( blackcolor )
    newim = Image.new(im.mode,im.size)
    newim.putdata(newimdata)
    return newim

redOrBlack(im).save(newImagePath)
   

# +
import numpy as np
import cv2
 
im = cv2.imread('output.png')
#set color to a set of pixels
im[np.where((im == [128,0,0]).all(axis = 2))] = [0,0,0]
cv2.imwrite('out4.png', im)

# +
import cv2 
 
im_gray = cv2.imread("brain.tif", cv2.IMREAD_GRAYSCALE)
im_color = cv2.applyColorMap(im_gray, cv2.COLORMAP_HSV)
# -

im_color
cv2.imwrite('colourHSV.png', im_color)

from numpy import array
from scipy.misc import toimage
img=toimage(im_color)
img

# +
import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('output.png', -1)
#cv2.imshow('GoldenGate',img)

color = ('b','g','r')
for channel,col in enumerate(color):
    histr = cv2.calcHist([img],[channel],None,[256],[0,256])
    plt.plot(histr,color = col)
    plt.xlim([0,256])
plt.title('Histogram for color scale picture')
plt.show()

while True:
    k = cv2.waitKey(0) & 0xFF     
    if k == 27: break             # ESC key to exit 
cv2.destroyAllWindows()

# +
import cv2
import numpy as np
from matplotlib import pyplot as plt
import operator

img = cv2.imread('output.png', -1)
cv2.imshow('Imagem:',img)

color = ('b','g','r')
qtdBlue = 0
qtdGreen = 0
qtdRed = 0
totalPixels = 0

for channel,col in enumerate(color):
    histr = cv2.calcHist([img],[channel],None,[256],[1,256])
    plt.plot(histr,color = col)
    plt.xlim([0,256])
    totalPixels+=sum(histr)
    print (histr)
    if channel==0:
        qtdBlue = sum(histr)
    elif channel==1:
        qtdGreen = sum(histr)
    elif channel==2:
        qtdRed = sum(histr)

qtdBlue = (qtdBlue/totalPixels)*100
qtdGreen = (qtdGreen/totalPixels)*100
qtdRed = (qtdRed/totalPixels)*100

#qtdBlue = filter(operator.isNumberType, qtdBlue)
#qtdGreen = filter(operator.isNumberType, qtdGreen)
#qtdRed = filter(operator.isNumberType, qtdRed)

plt.title("Red: "+str(qtdRed)+"%; Green: "+str(qtdGreen)+"%; Blue: "+str(qtdBlue)+"%")
plt.show()
# -



StarcoderdataJupyterScriptsDedupFiltered