How to convert cell operations into C++

1 view (last 30 days)
Deepak Achar
Deepak Achar on 14 May 2015
Answered: Walter Roberson on 18 May 2015
Hello
I am not getting how to convert the cell operations in this code to C++. Please anyone get me the solution for this problem. Thank you.
clc
clear all;
close all;
%#codegen
% Reading target image and secret image
x=imread('C:\Users\DEEPAK\Desktop\project\code\final project code\B.bmp');
l=1;
[m n o]=size(x);
% Creating secret image tiles for R G B Color Channels
for k=1:3
for i=1:4:m
for j=1:4:n
x1{k,l}=x(i:i+3,j:j+3,k);% secret images tiles in an array
y1(k,l)=mean2(x1{k,l});
l=l+1;
end
end
l=1;
end
Regards Deepak
  1 Comment
Geoff Hayes
Geoff Hayes on 17 May 2015
Deepak - why are you using a cell array for x1? Why can't you just use a multidimensional matrix to store this data (is it even necessary to store this data)? As an aside, if m is the number of rows of x and i iterates from 1 to m in steps of four, could you not have a problem for the case where i is identical to m and you try to access
x(m:m+3,...)
because m+3 is exceeds the (row) dimension of the array?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 18 May 2015
malloc() a pointer to a data area large enough to store the required information. Copy the data into the resulting array. Store the pointer in the appropriate element of x1.
In C you must decide whether you are going to store the sub-arrays as rectangular blocks, or if instead you are going to store them as a vector of pointers to row vectors. The vector of pointers is easier to find examples of; see http://c-faq.com/aryptr/dynmuldimary.html, but rectangular blocks is more memory efficient and is the way that MATLAB handles it.
Side note: you will have a difficult time finding code to replace imread()

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!