Ask Your Question
0

how to make a new mat variable with 9 elements

asked Oct 19 '14

Deepak Kumar gravatar image

updated Oct 20 '14

Hi, I want make a new mat variable (image) of 9 element where i can add the 4 pixel of a mat image in its corner and the row and colums in the mat, and in the middle the mat image itself. How i can do this? I am not able to create a mat variable with 9 elements.

I have done this in matlab.

I=imread('1.jpg');
in= im2double(rgb2gray(I));
[row col]=size(in);
h = ones(5);
out1=stdfilt(in,h);   %Standard deviation from inbuilt function
imshow(out1);

%% Replicating two rows and two columns on all the four sides of image
image1=[ in(1,1), in(1,:), in(1,col);
        in(:,1), in,      in(:,col);
        in(row,1), in(row,:), in(row,col)];

Here in(1,1),in(1,col),in(row,1), in(row,col) are the 4 corner of new mat variable, and in is the previous mat image and else are the boundaries of the new mat variable.

This is like adding a row and a column in existing image, so that i can do furter calcualtion.

help me.

thanks

Preview: (hide)

2 answers

Sort by » oldest newest most voted
2

answered Oct 20 '14

berak gravatar image

updated Oct 20 '14

you can use the builtin ( but undocumented ;[ ) copyMakeBorder() (from core):

// Mat_<uchar> is only here for ease of demonstration
Mat_<uchar> inner(3,3); inner << 1,2,3,4,5,6,7,8,9;

Mat outer = Mat(inner.rows+2, inner.cols+2, inner.type());
copyMakeBorder(inner,outer ,1,1,1,1,BORDER_REPLICATE);

cerr << inner << endl;
cerr << outer << endl;

[  1,   2,   3;
   4,   5,   6;
   7,   8,   9]
[  1,   1,   2,   3,   3;
   1,   1,   2,   3,   3;
   4,   4,   5,   6,   6;
   7,   7,   8,   9,   9;
   7,   7,   8,   9,   9]
Preview: (hide)
0

answered Oct 20 '14

This is not possible in OpenCV with the standard cv::Mat. cv::Mat is based on a 1-d array that contains the pixel values so that every entry in your matrix has to have the same type.

But what do you mean by mat file? Do you just want to store these values? In this case a yaml-file could help you: http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html

Preview: (hide)

Comments

NO i dont want to store these value, i want to create a new mat image which contains one extra row in top and one extra column in left side of previous image and should be able to access its pixels.

Deepak Kumar gravatar imageDeepak Kumar (Oct 20 '14)edit

Ah sorry. I misunderstood you completely...

FooBar gravatar imageFooBar (Oct 20 '14)edit

Question Tools

Stats

Asked: Oct 19 '14

Seen: 414 times

Last updated: Oct 20 '14