![]() |
Forum Index : Microcontroller and PC projects : IMAGE ROTATE
Page 1 of 4 ![]() ![]() |
|||||
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Is there a way to do the image rotate command that the colour micromite 2 has on a version of MM that doesn't have that command using basic? Edit: I don't think it's possible to use CSUB on pi-cromite 5.05.01 Edited 2021-01-08 05:34 by lew247 |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Sure: I won't give you the code but here's the procedure: You want to drive the iteration from the destination image, not the source image. Let's suppose the destination image is N x M pixels. So you iterate like this: for i = 1 to N for j = 1 toi M destination_pixel(i, j) = some_function( some_source_pixels) next k next i The exact nature of some_function() depends on things like the coordinates of the center of rotation in your source image, the angle of rotation, and what kind of interpolation you want to use, e.g. bilinear. Just Google and look at the Wikipedia article on image rotation for details. -Bill |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
It will be slow compared to the firmware version. -Bill |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10070 |
Have a look at this |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thank you all Forgot to mention BLIT doesn't work either Thanks anyway Peter ![]() Edited 2021-01-08 06:13 by lew247 |
||||
NPHighview![]() Senior Member ![]() Joined: 02/09/2020 Location: United StatesPosts: 202 |
Something I've used in the past, from development of a medical ultrasound imaging instrument, is "scan conversion". In ultrasound, you want to display an image acquired in (r, theta) on an (x,y) graphics display. Conceptually, what you're trying to do is display an (x', y') "signal" on an (x,y) graphics display, so you can apply the same techniques of angle rotation and interpolation, but do so from one rectilinear area to another. Take a look at this: https://people.eecs.berkeley.edu/~ug/slide/pipeline/assignments/scan/ This alludes to some of the interpolation problems you might encounter. If, for instance, the transformation of integer x and y coordinates result in fractional x' and y' coordinates, you may need to sample the surrounding source pixels, and use the "weights" of the fractional parts to perform a weighted average of the colors of the source pixels to figure out what color the destination pixel should be. This generalizes to scaled figures as well as rotated figures. Hope this helps - Best of luck! Live in the Future. It's Just Starting Now! |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1122 |
Which MM device? Some don't maintain an image buffer in which case a rotate is nigh on impossible. You might be able to build an image stored in variables and rotate that as you display it. Visit Vegipete's *Mite Library for cool programs. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10070 |
Blit is just a memory copy - easy to hand code a replacement: read a pixel, write a pixel |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
It's not actually for an image as such it's for this part of the code for the CMM2 written by yock1960 text 10,10,"NE",L,7,,RGB(WHITE),RGB(BLACK) image rotate 6,4,30,30,cx%+wid%/2,cy%-wid%/2,45 text 10,10,"SE",L,7,,RGB(WHITE),RGB(BLACK) image rotate 6,4,30,30,cx%+wid%/2,cy%+wid%/2,135 text 10,10,"SW",L,7,,RGB(WHITE),RGB(BLACK) image rotate 6,4,30,30,cx%-wid%/2,cy%+wid%/2,225 text 10,10,"NW",L,7,,RGB(WHITE),RGB(BLACK) image rotate 6,4,29,29,cx%-wid%/2,cy%-wid%/2,315 from this post I understand a little bit of this but when it's text how do you know exactly where the X and Y positions? in the example below the X and Y positions are 10,10 yet the rotate is 6 and 4 I'm guessing the page number doesn't matter? image rotate 6,4,30,30,cx%+wid%/2,cy%-wid%/2,45 IMAGE ROTATE x, y, width, height, new_x, new_y, angle! [,page_number] My hdmi monitor is 1600 x 900 In my code instead of using Mode I've used mm.hres = 800 mm.vres = 600 because I couldn't figure out how to position it on my display in the place I wanted dim cx% = 785 dim cy% = 238 dim wid% = 105 I've tried to digest and understand how to position and size it without having to use the mm.hres/mm.vres and also understand how to do as Peter suggested, moving one pixel at a time but as I don't understand how to do this when it comes to text , other than writing blank spaces before updating the text Edit: i really with there was one Pi software version that could be used for MM even if it never got updated, I know people will disagree about the updates but for our purposes here it's mostly irrelevant as most projects will be standalone projects. Matherp If you do decide to revisit Pi-cromite this is the version of Stretch and MMbasic with everything other than Blit working and this is the version of Pigpio that works with this If it helps at all and I know you're highly unlikely to revisit it Edited 2021-01-08 18:33 by lew247 |
||||
yock1960 Senior Member ![]() Joined: 18/08/2020 Location: United StatesPosts: 167 |
I worked on that code quite a bit more after that...it was like an 'ear worm'! ![]() Here it is, in a little demo, but contains a standalone 'compass' subroutine. Basically, I had to use trig functions for everything. Steve Compass.zip ![]() Edited 2021-01-08 19:30 by yock1960 |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
That code looks amazing. It's just a shame it won't work on Pi-Cromite This is what I've done with your previous code The red triangle rotates to the current wind direction Lewis Edited 2021-01-08 19:35 by lew247 |
||||
yock1960 Senior Member ![]() Joined: 18/08/2020 Location: United StatesPosts: 167 |
Nice! ![]() Steve |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Updated it For some reason the vertical line isn't pointing directly north and south and I can't figure out why This is my "modified" version of your code for some reason the intermediate direction markers aren't working they go off the screen, NE, SE etc and Image rotate won't work on Pi-Cromite which is why it's commented out CLS color RGB(WHITE),RGB(134,174,230) dim cx% = 785 ' off by 15 due to how rotate image works (or something) dim cy% = 238 ' ditto dim wid% = 105 ' radius dim ang! = 0.087266463 '5 degrees in radians dim rad90! = 1.570796327 '90 degrees in radians compass_rose cx%, cy%, wid% sub compass_rose cx%,cy%,wid% local a% ' cardinal directions text cx%+9,cy%+15-(wid%+22),"N",L,2,,RGB(BLACK),RGB(134,174,230) text cx%+9,cy%+15+(wid%+5),"S",L,2,,RGB(BLACK),RGB(134,174,230) text cx%+wid%+18,cy%+4,"E",L,2,,RGB(BLACK),RGB(134,174,230) text cx%-(wid%+5),cy%+4,"W",L,2,,RGB(BLACK),RGB(134,174,230) ' tick marks, every 5 degrees (360/5 = 72) for a% = 0 to 71 line (cx%+15)+(cos(a%*ang!)*(wid%-4)),(cy%+15)-(sin(a%*ang!)*(wid%-4)),(cx%+15)+(cos(a%*ang!)*(wid%+1)),(cy%+15)-(sin(a%*ang!)*(wid%+1)),,RGB(WHITE) next ' compass perimiter circle cx%+15,cy%+15,wid% circle cx%+15,cy%+15,wid%-4 ' pointers to intermediate directions (not sure why I need 1 to 8 here!, besides bad math :-) ) for a% = 1 to 8 triangle cx%+15-sin(9*a%*ang!)*wid%*.5,cy%+15-cos(9*a%*ang!)*wid%*.5,cx%+15+cos(9*a%*ang!)*wid%*.07,cy%+15-sin(9*a%*ang!)*wid%*.07,cx%+15-cos(9*a%*ang!)*wid%*.07,cy%+15+sin(9*a%*ang!)*wid%*.07,RGB(WHITE),RGB(WHITE) next line cx%+15-sin(9*a%*ang!)*wid%*.5,cy%+15-cos(9*a%*ang!)*wid%*.5,cx%+15+sin(9*a%*ang!)*wid%*.5,cy%+15+cos(9*a%*ang!)*wid%*.5,,RGB(BLACK) line cx%+15-sin(9*a%*ang!)*wid%*.5,cy%+15+cos(9*a%*ang!)*wid%*.5,cx%+15+sin(9*a%*ang!)*wid%*.5,cy%+15-cos(9*a%*ang!)*wid%*.5,,RGB(BLACK) ' pointers to cardinal directions for a% = 0 to 3 triangle cx%+15-sin(a%*rad90!)*(wid%+2),cy%+15-cos(a%*rad90!)*(wid%+2),cx%+15+cos(a%*rad90!)*wid%*.11,cy%+15+sin(a%*rad90)*wid%*.11,cx%+15-cos(a%*rad90!)*wid%*.11,cy%+15-sin(a%*rad90!)*wid%*.11,RGB(RED),RGB(RED) next line cx%+15,cy%+15+wid%*.99,cx%+15,cy%+15-wid%*.99,,RGB(BLACK) line cx%+15-wid%*.99,cy%+15,cx%+15+wid%*.99,cy%+15,,RGB(BLACK) circle cx%+15,cy%+16,wid%*.18,,,RGB(BLACK),RGB(GREEN) circle cx%+15,cy%+16,wid%*.13,,,RGB(BLUE),RGB(BLUE) circle cx%+15,cy%+16,wid%*.04,,,RGB(YELLOW),RGB(YELLOW) end sub Edited 2021-01-08 20:40 by lew247 |
||||
yock1960 Senior Member ![]() Joined: 18/08/2020 Location: United StatesPosts: 167 |
I just print the intermediate directions in an arbitrary place, then image rotate them into the correct place. You would need to do something similar to that used for the Cardinal directions. Steve |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Unfortunately there is no image rotate command in my version of MM I'll have to try and work out how to turn them pixel by pixel or leave them out |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
And what if you prepare images for every 10 grads (=36 images)? When they will be monochrome, they are pretty small... (and you can color it later in programm, when needed) Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
ooh nice thinking ![]() |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Does anyone know what the exact font is? it's font 2 which I believe is 12x20 but it doesn't say in the manual which font family I'd like to make the images the same font if possible |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10070 |
I've built a version of MMBasic using the version of stretch and pigpio you provided. Please could you run your application on it and see if it works. If it does I can then look at updating it mmbasic.zip PS Blit works perfectly for me OPTION LCDPANEL HDMI and then I can run the rotate program I linked with no changes. Check the syntax: BLIT xold, yold, xnew, ynew, width, height Edited 2021-01-08 23:05 by matherp |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Sorry for the delay Peter I was trying several different codes Everything seems to work perfectly OTHER than Blit This doesn't work Code used and image attached Code.zip EDIT what's the code you linked? I['ll try that Edited 2021-01-09 00:24 by lew247 |
||||
Page 1 of 4 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |