How to change matlab stores image data for C++

A
Amr Mhish · Aug 30, 2022 · 2K views
Question
Hello everybody i am writing a Program using C++ with OpenCV library! and I am using a function generated by Matlab Mex which takes an image and returns values! it look something like this   array=findsomething(image);//matlab function the image is a OpenCV variable which called Mat! this Mat stores the pixels in a unsigned char array as BGR. while Matlab function stores the pixels in RGB array. converting the data between the OpenCV variable and the Matlab Function variable means copying each pixel from the first variable Mat into Unsigned Char *array(this is the Matlab function Variable) which takes a really long time for each i call an image from the camera. is there a way to change how Matlab stores and handles the image data to become BGR ?
Expert Answer
Profile picture of Neeta Dsouza
Neeta Dsouza PhD Expert
Answered Aug 23, 2026
No, you cannot change the order of the colour channels in matlab (don't know about OpenCV). However, if you don't display the image nor convert it to grayscale, the order of the channels doesn't matter for most processing functions.
 
Converting between RGB and BGR in matlab should be fairly quick:
 
 
flip(yourimage, 3)

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!