Is there a built-in function for conversion of BGRA8 image to RGB image? If there is no available function for the conversion, is there a way to make this conversion?

 採用された回答

Jan
Jan 2021 年 10 月 12 日

1 投票

Do you have the pixels values as UINT8 array already? Then:
RGB = BGRA8(:, :, [3, 2, 1])

7 件のコメント

L
L 2021 年 10 月 13 日
Hello Jan,
Thank you for the response.
I have the vector of BGRA8 data, 1010688x1, uint8.
This is a color image with dimensions 376x672 (height x width) in BGRA8 format.
According to the documentation, this means that each pixel is 32bit sized and contains in order the BLUE, the RED, the GREEN and the ALPHA channel values.
How and when should I apply your statement? I need only the RGB image.
Thank you.
L
L 2021 年 10 月 13 日
Also, I have now a new problem with accessing the structure.
Here is the screenshot. That is the problem here. Yesterday I was able to access the Data field in the Command Window.
Image Analyst
Image Analyst 2021 年 10 月 13 日
What is rossubscriber? What do these show?
methods(sub)
fieldnames(sub)
properties(sub)
L
L 2021 年 10 月 13 日
Hi,
The sub is the rossubcriber. I have subscribed to a ROS topic, and I have received the ROS message with the BGRA8 image in it. The Data field contain the image vector 1010688x1 uint8.
Yesterday I have accessed the field with img=sub.LatestMessage.Data. Now, I have the error.
L
L 2021 年 10 月 13 日
L
L 2021 年 10 月 13 日
I have accessed the field again in the Command Window, but my RGB image is wrong.
Maybe there is a problem with the array conversion?
L
L 2021 年 10 月 13 日
編集済み: L 2021 年 10 月 13 日
The issue with the structure is solved. The solution is to call the receive() function.
But, still there is a problem with the conversion from BGRA8 to RGB.
What can be the problem here?
Here is the screenshot, and the code. The BGRA8 image is 1010688x1 uint8 array.
msg = receive(sub);
img=msg.Data;
outImg = reshape(img, 672, 376, []);
outImg1=permute(outImg, [2 1 3 4]);
rgb=outImg1(:,:,[2 1 3]);
figure, imshow(rgb);

サインインしてコメントする。

その他の回答 (1 件)

Cam Salzberger
Cam Salzberger 2021 年 10 月 13 日

0 投票

Since the image data is coming out of a ROS message, you can use the ROS functions to extract the image from it:
Message object - readImage method
Message struct - rosReadImage function
-Cam

1 件のコメント

L
L 2021 年 10 月 16 日
Thank you, the problem is solved now

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Image Processing Toolbox についてさらに検索

製品

質問済み:

L
L
2021 年 10 月 12 日

コメント済み:

L
L
2021 年 10 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by