If I read an image with opencv save it, and read it again, does this lead to the image being loaded in RGB ordering?

huangapple go评论72阅读模式
英文:

If I read an image with opencv save it, and read it again, does this lead to the image being loaded in RGB ordering?

问题

我在想,因为我注意到如果我使用OpenCV保存图像而不将图像重新排序为RGB,它们将以BGR顺序保存。
现在我已经打开并重新排序了图像(使用cv2.cvtColor(image, cv2.COLOR_BGR2RGB)),我不确定排序是否正确?
因为如果它交换了第一个和最后一个通道(R->B)并将其保存为(BGR),那么在第二次加载时,这将再次变为RGB对吧?

如果这个问题有点愚蠢,我道歉。

提前致以诚挚的谢意!

例如

  1. image = cv2.imread(path) # RGB -> BGR
  2. cv2.imwrite(image, path) # 保存为BGR
  3. image = cv2.imread(path) # 图像的排序是什么?
英文:

I was wondering, since I noticed that if I save an image with opencv, without reordering the images back to RGB, they're saved in BGR ordering.
Now I have opened and reordered (using cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) and I am unsure if the ordering is correct?
Because if it switches the first and last channel (R->B) and saves it as (BGR) than on the second load this would be RGB again right?

I apologize if this is a bit of a silly question.

Many thanks in advance!

for example

  1. image = cv2.imread(path) #RGB ->BGR
  2. cv2.imwrite(image, path) # saves BGR
  3. image = cv2.imread(path) # what is the ordering of image?

答案1

得分: -1

考虑以下图片

If I read an image with opencv save it, and read it again, does this lead to the image being loaded in RGB ordering?

让我们尝试一下,看看如果我们一遍又一遍地在opencv中加载它,它是否会发生变化。

  1. im = cv.imread("blue.jpg")
  2. cv.imwrite("blue2.jpg", im)
  3. im = cv.imread("blue2.jpg")
  4. cv.imwrite("blue3.jpg", im)

如果我正确理解了你的问题,你认为第二张图片,blue2.jpg是一张红色的图片。至少在这里是这样的

我注意到如果我使用opencv保存一张图片,而不重新排列图片回到RGB,它们会以BGR的顺序保存。

结果

blue2.jpg:

If I read an image with opencv save it, and read it again, does this lead to the image being loaded in RGB ordering?

blue3.jpg:

If I read an image with opencv save it, and read it again, does this lead to the image being loaded in RGB ordering?

结论

仅仅读取和写入图像文件不会改变结果的颜色通道的顺序。即imwrite(imread(.))并不等同于cvtColor(im, cv.BGR2RGB)

英文:

Consider the following image

If I read an image with opencv save it, and read it again, does this lead to the image being loaded in RGB ordering?

Let's try if it changes if we load it in opencv over and over again.

  1. im = cv.imread("blue.jpg")
  2. cv.imwrite("blue2.jpg", im)
  3. im = cv.imread("blue2.jpg")
  4. cv.imwrite("blue3.jpg", im)

If I understood your question correctly, you assume that the second image, blue2.jpg is a red image. That is at least what you claim here

> I noticed that if I save an image with opencv, without reordering the images back to RGB, they're saved in BGR ordering.

Results

blue2.jpg:

If I read an image with opencv save it, and read it again, does this lead to the image being loaded in RGB ordering?

blue3.jpg:

If I read an image with opencv save it, and read it again, does this lead to the image being loaded in RGB ordering?

Conclusions

Merely reading and writing the image files does not change the order of the color channels of the result. i.e. imwrite(imread(.)) does not equal to cvtColor(im, cv.BGR2RGB).

huangapple
  • 本文由 发表于 2023年3月12日 19:32:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712826.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定