【问题标题】:Changing Colours and Counting Pixels in Python在 Python 中更改颜色和计算像素
【发布时间】:2015-11-06 20:51:32
【问题描述】:
def change(pic, startX, startY, getHeight, getWidth, endColour): 
  width = getWidth
  height = getHeight 
  picture = makePicture(pic)
  for px in getPixels(picture):
    x = getX(px)
    y = getY(px)
    if (startX <= x <= getHeight) and (startY <= y <= getWidth):
      if (distance(black, getColor(px)) < 95):
        setColor(px, endColour)
  show (picture)
  return (picture)

这是我到目前为止的代码。我需要做的是将照片中黑色像素的中间 1/3 更改为红色,将黑色像素的底部 1/3 更改为黄色,并在照片上打印更改为多少黑色像素黄色,有多少变成了红色。我对 JES 和 Jython 以及整体编程非常陌生,因此我们将不胜感激!

【问题讨论】:

    标签: python jes


    【解决方案1】:

    您应该添加您谈论的内容:https://github.com/gatech-csl/jes

    我调整了您的代码以向您展示如何打印一些输出:

    def change(pic, startX, startY, endColour): 
      picture = makePicture(pic)
      width = getWidth
      height = getHeight 
      changedPixels = 0
      for px in getPixels(picture):
        x = getX(px)
        y = getY(px)
        if (startX <= x <= height) and (startY <= y <= width):
          if (distance(black, getColor(px)) < 95):
            changedPixels = changedPixels + 1
            setColor(px, endColour)
      show (picture)
      print "I changed", changedPixels, "pixels"
      return (picture)
    

    我的 JES 控制台:

    ======= Loading Program =======
    >>> change('demos/image.jpg', 2, 2, makeColor(0,0,0))
    I changed 11214 pixels
    Picture, filename /home/marty/Downloads/jes-5.020-linux/demos/image.jpg height 234 width 313
    >>> 
    

    这应该足以作为示例,以便您完成作业。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多