tkinter - When resizing color image, it shows up in red scale only

时间:2017-08-30 20:03:06

标签: python user-interface opencv tkinter

I have the following piece of code:

Sam <- c("222-88", "537-457", "652-1", "787-892")
var <- LETTERS[1:4]
df <- data.frame(Sam, var)

library(dplyr)
library(tidyr)
library(stringr)

df %>% 
  separate(Sam, c("sam1", "sam2")) %>% 
  mutate(Sam = str_c(sam1, "-", str_pad(sam2, 3, "left", "0"))) %>% 
  select(-sam1, -sam2)

#>   var     Sam
#> 1   A 222-088
#> 2   B 537-457
#> 3   C 652-001
#> 4   D 787-892

# OR

df %>% 
  mutate(
    sam_new = str_c(
      str_extract(Sam, "^\\d+-"),
      str_extract(Sam, "\\d+$") %>% str_pad(3, "left", "0")
    )
  )

#>       Sam var sam_new
#> 1  222-88   A 222-088
#> 2 537-457   B 537-457
#> 3   652-1   C 652-001
#> 4 787-892   D 787-892

I am reading in color .tif images and then trying to display them in the https://developers.facebook.com/apps/<YOUR_APP_ID>/marketing-api/tools/ However, when I go to do that, it shows the normal color image only in red scale even though I never extracted just the red signal. I am completely unable to diagnose the issue. How do I fix this issue?

Ultimately, what I want to do is display two images on this GUI. An original image on the left and a modified image on the right. Currently my gui layout is set up as I've coded above. However, if you think there is an easier way to do this, then I'd be interested to hear.

2 个答案:

答案 0 :(得分:1)

这是因为opencv使用BGR而不是RGB。当您使用此行时:self.img = Image.fromarray(np.array(self.img).copy())正在交换蓝色和红色。在你使用上面的代码之前,在opencv中将BGR转换为RGB,你应该很高兴。

self.img = cv2.cvtColor(self.img,cv2.COLOR_BGR2RGB)

答案 1 :(得分:0)

我看到你正在使用opencv。为什么不使用opencv命令来调整大小。      它很简单,效果很好。

看看这个页面:

OpenCV Resize

这是使图像缩小50%的示例,或者代替fx和fy,您可以放置​​所需的确切尺寸。

thumbnail = cv2.resize(image, (0,0), fx=0.5, fy=0.5) 
相关问题