Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 20:50 19 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : IMAGE ROTATE

     Page 1 of 4    
Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 07:26pm 07 Jan 2021
Copy link to clipboard 
Print this post

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 States
Posts: 386
Posted: 07:38pm 07 Jan 2021
Copy link to clipboard 
Print this post

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 States
Posts: 386
Posted: 07:39pm 07 Jan 2021
Copy link to clipboard 
Print this post

It will be slow compared to the firmware version.
-Bill
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8607
Posted: 07:44pm 07 Jan 2021
Copy link to clipboard 
Print this post

Have a look at this
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 07:55pm 07 Jan 2021
Copy link to clipboard 
Print this post

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 States
Posts: 197
Posted: 09:37pm 07 Jan 2021
Copy link to clipboard 
Print this post

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: Canada
Posts: 1085
Posted: 10:07pm 07 Jan 2021
Copy link to clipboard 
Print this post

  lew247 said  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?

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 Kingdom
Posts: 8607
Posted: 10:37pm 07 Jan 2021
Copy link to clipboard 
Print this post

  Quote  Forgot to mention BLIT doesn't work either


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 Kingdom
Posts: 1676
Posted: 08:00am 08 Jan 2021
Copy link to clipboard 
Print this post

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 States
Posts: 167
Posted: 09:14am 08 Jan 2021
Copy link to clipboard 
Print this post

  lew247 said  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


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 Kingdom
Posts: 1676
Posted: 09:30am 08 Jan 2021
Copy link to clipboard 
Print this post

  yock1960 said  

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


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 States
Posts: 167
Posted: 09:54am 08 Jan 2021
Copy link to clipboard 
Print this post

Nice!  

Steve
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 10:09am 08 Jan 2021
Copy link to clipboard 
Print this post

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 States
Posts: 167
Posted: 10:38am 08 Jan 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1676
Posted: 10:41am 08 Jan 2021
Copy link to clipboard 
Print this post

  yock1960 said  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

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 Republic
Posts: 532
Posted: 11:01am 08 Jan 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1676
Posted: 11:11am 08 Jan 2021
Copy link to clipboard 
Print this post

  jirsoft said  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)

ooh nice thinking  
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 11:30am 08 Jan 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 8607
Posted: 12:21pm 08 Jan 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1676
Posted: 02:24pm 08 Jan 2021
Copy link to clipboard 
Print this post

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    
Print this page
© JAQ Software 2024