How to make my patch simpler
Here is what I am trying to do.
I intend to divide a real time video from webcam 1024 times. (32 by 32 mosaic). Each mosaic is the video itself played live and the overall look of the mosaic is also the video. See attached pic from a screen shot. I am able to use jit.scissors and jit. matrix and jit.brcosa to divide the real time video, calculate the value in each mosaic and apply it to the overall video.
The problem is that I got an over complicated patch. It is able to make part of the video a mosaic effect but it to the limit the if I add more mosaic (jit.scissors and jit. matrix and jit.brcosa combinations), Max/msp program always automatically quit. And the memory of my computer is extremely low. I tried on 8 core, 8gb ram iMac. In attached picture 5.jpg, you can tell how complicated the patch is.
Is there any way to simply the patch?
wow, heavy copy pasting going on there :)
take a look at tinyvideo example.
dissect it and you will gain many XP points at matrix manipulation.
Recipe 36: TinyVideo
man, I hope you had max toolbox to help you with the patch cord connections!
you likely can streamline some of your processes and still get the effect you want—for example, I don’t think you need [jit.iter], there’s probably a way to do it all at once. that alone is bogging things down tremendously I’m sure.
a smaller time-saver (but a good one for computers in general)—never divide when you can multiply, so swap your [/ 255] for the reciprocal, and multiply instead. Paste Replace is your friend here…
@seejayjames i’m pretty new to maxtoolbox…
do you have any other suggested tools ?
that’s a good one, not sure of others. it takes a bit to get used to and there’s no undo, so that’s something to remember about it. however you can get pretty darn quick with patching once you get the hang of the shortcut keys :)
Thanks all. you guys are genius. This is a project for a beginner Max/Msp class I took. thanks for all the suggestions. I definitely will look into them, I knew there is some way to make it simpler.
I was a copy/paste maniac.
@seejayjames if I do not dissect the video, how do I know the average value and apply it to each mosaic video? or I am totally missing some easier ways to do this?
I’m no jitter expert but I think if you reduce the resolution of the original matrix by putting it into another 32*32 matrix it automatically will give you the average of each pixel of your new 32*32 matrix, and then just iterate through each element of the reduced version….?? something like that
exactly, put it into a 32 * 32 and use whichever plane(s) you want to get the brightness value, or run through [jit.rgb2luma] to get the luminance. Then you can use each pixel to multiply by each chopped video in the mosaic. In fact you could use jit.glue to attach everything back together in the big video, then use jit.op @op * and multiply by the "luminance matrix", which would do it all at once.
Lots of ways to simplify the "stepping through" of the luminance pixels if you go that route, you might try using send/receives with [prepend] and index numbers instead of patch cords, look to [patcherargs] or use abstractions with arguments, try [jit.spill] to go row by row, etc. 32 * 32 is a lot of iterating, so it might be a good opportunity to try these other techniques and show off to the rest of the class ;-)
OK, it’s even simpler than that, if all you want is to mosaic the original video, you can just use the zoom of [jit.rota]:
jit.rota @x_zoom 0.03125 @y_zoom 0.03125 @boundmode 2
0.03125 = 1 / 32, so that will zoom out x and y by a factor of 32, and boundmode 2 will ensure that the image repeats.
original matrix–>32 * 32 matrix–>jit.rgb2luma–>jit.op @op *
to make the overall luminance affect each square, you’re multiplying the luma-matrix by the original full-sized one (which has been zoomed out already).
Tweak the x_zoom and y_zoom to suit…you can easily change the 32 * 32 matrix to be a new size, and tie it (or not) to the zoom factors…some really fun stuff there. To tie it, run (for example) 32 through [!/ 1.] to get the reciprocal, which you need for the zoom factor.
And it will definitely not freeze the machine—this is tons less computation. So you have more CPU for other fun effects…!
Does anyone got that patch? would love to try and experiment on it!
this is an implementation as described in the previous post by seejay, but without the rgbtoluma step:
----------begin_max5_patcher---------- 1257.3oc0Ys1jZpCF9y3uhbX5mNi0RBWTNep82QmNNQHqls.gBwUa6z+6mPB nIJ5BrtVblcCxat8jm7dI4keOwxdEaOozF7efuBrr98DKKonJAV0uaYmh2Gk fKkMyNiris5Y6opp3j8bo3DFNNkTVBfAM0ksMklkP3x9AqEli4QanYqWVPh3 p4Et.NyYp3QU4bW4uCm4.9VcWdhkwyvoD477kBJNoYFnwRYB77QzBsokske5 7pDw+YNQMo11FieI8WxJfBnTI8OSlTUL8sQJ4fewXoCjOB7qJ8lOP9Xd67A5 h7wzqwI5nkTTyD0Tgn0zDxKjhRJKSasYYiyy0Dao0kJ96Ylbf7mdPDMSIBdP TA4EZS+CUBE6JSZprgxbpHIYQfm7g2BmiLlX2acBK56DI83zHLl7T2GAVNIq sV2TX1RZVdAojjww7ZvqOq3sI7ksyvl0+DNhbwN2pJfk85BZLKqBDF8rRbyz ITwj5VUkG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