Ask Your Question
0

how to make a new mat variable with 9 elements

asked 2014-10-19 13:17:25 -0600

Deepak Kumar gravatar image

updated 2014-10-20 03:39:45 -0600

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2014-10-20 04:29:55 -0600

berak gravatar image

updated 2014-10-20 05:19:17 -0600

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]
edit flag offensive delete link more
0

answered 2014-10-20 01:37:09 -0600

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

edit flag offensive delete link more

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 ( 2014-10-20 02:21:41 -0600 )edit

Ah sorry. I misunderstood you completely...

FooBar gravatar imageFooBar ( 2014-10-20 07:26:39 -0600 )edit

Question Tools

Stats

Asked: 2014-10-19 13:17:25 -0600

Seen: 284 times

Last updated: Oct 20 '14