英文:
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对吧?
如果这个问题有点愚蠢,我道歉。
提前致以诚挚的谢意!
例如
image = cv2.imread(path) # RGB -> BGR
cv2.imwrite(image, path) # 保存为BGR
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
image = cv2.imread(path) #RGB ->BGR
cv2.imwrite(image, path) # saves BGR
image = cv2.imread(path) # what is the ordering of image?
答案1
得分: -1
考虑以下图片
让我们尝试一下,看看如果我们一遍又一遍地在opencv中加载它,它是否会发生变化。
im = cv.imread("blue.jpg")
cv.imwrite("blue2.jpg", im)
im = cv.imread("blue2.jpg")
cv.imwrite("blue3.jpg", im)
如果我正确理解了你的问题,你认为第二张图片,blue2.jpg
是一张红色的图片。至少在这里是这样的
我注意到如果我使用opencv保存一张图片,而不重新排列图片回到RGB,它们会以BGR的顺序保存。
结果
blue2.jpg
:
blue3.jpg
:
结论
仅仅读取和写入图像文件不会改变结果的颜色通道的顺序。即imwrite(imread(.))
并不等同于cvtColor(im, cv.BGR2RGB)
。
英文:
Consider the following image
Let's try if it changes if we load it in opencv over and over again.
im = cv.imread("blue.jpg")
cv.imwrite("blue2.jpg", im)
im = cv.imread("blue2.jpg")
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
:
blue3.jpg
:
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)
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论