Discuss Scratch

gtoal
Scratcher
1000+ posts

simple image processing?

Is it possible to manipulate the rasters of sprites in ways other than the default such as ‘swirl’ etc? I'ld like to project a sprite using an affine transfer onto the wall of a 3D maze (like a texture on a wall in Doom etc) in order to create a walk-through art gallery with paintings on the walls. Is this possible in Scratch? I can't find any mechanism that would let me do it.

thanks

G
GP1
Scratcher
100+ posts

simple image processing?

In default Scratch; no. Some mods MIGHT be able to have that capability (Snap! has a lot of features, but I don't think quite enough to what you need it for). Not to my knowledge, anyway.
keanudag
Scratcher
1 post

simple image processing?

I'd say you would have to scan a picture by moving another sprite around on it as a sprite and saving the colors in a list and then manipulate them and cast them on the position you want them on, but that would be extremely slow and relatively complicated but in scratch it would be the only possibility.
DigiTechs
Scratcher
500+ posts

simple image processing?

It would be possible, but you probably would have to store each pixel's RGB colour and find out a way to turn RGB into HSV, and then draw that using the pen.

That or you just directly store each pixel's HSV colour instead and then you don't have to turn RGB into HSV.
bobbybee
Scratcher
1000+ posts

simple image processing?

Alternatively, if you're so knowledgable about this, why not store the images as HSV in a list and just draw that in pen on-demand?

(generated with an outside script. I could write a script, probably)
TheLogFather
Scratcher
1000+ posts

simple image processing?

May be worth noting that Scratch's standard “set pen color” block works with a 24 bit RGB value (i.e. one component per byte), so you wouldn't want to turn into HSV/HSL:
set pen color to ( ( ( (red) * (65536) ) + ( (green) * (256) ) ) + (blue) )
The above is the “set pen color” block that usually shows a colour-picker square (but you can also drop an expression/variable into it) - it's not the one that sets something analogous to the pen ‘hue’ (with an effective range of zero to 200ish).

Along with “set pen shade” (which gives something analogous to lightness), that other "set pen should be more like hue not color" block gives you two out of three components of a HSL colour-space. Since saturation is missing, you can't go from RGB to a full HSL space just using those two pen blocks…


To get a feel for the amount of work (i.e. processing) required for Scratch to render something along the lines asked by the OP (and maybe to bring some kind of practical conclusion to this thread?), take a look at this rotatable textured sphere project, and this rotatable textured cube project.

amgames
New Scratcher
100+ posts

simple image processing?

TheLogFather wrote:

May be worth noting that Scratch's standard “set pen color” block works with a 24 bit RGB value (i.e. one component per byte), so you wouldn't want to turn into HSV/HSL:
set pen color to ( ( ( (red) * (65536) ) + ( (green) * (256) ) ) + (blue) )
The above is the “set pen color” block that usually shows a colour-picker square (but you can also drop an expression/variable into it) - it's not the one that sets something analogous to the pen ‘hue’ (with an effective range of zero to 200ish).

Along with “set pen shade” (which gives something analogous to lightness), that other "set pen should be more like hue not color" block gives you two out of three components of a HSL colour-space. Since saturation is missing, you can't go from RGB to a full HSL space just using those two pen blocks…


To get a feel for the amount of work (i.e. processing) required for Scratch to render something along the lines asked by the OP (and maybe to bring some kind of practical conclusion to this thread?), take a look at this rotatable textured sphere project, and this rotatable textured cube project.

…wow. Have some magical internet points.

I didn't know about being able to set the pen to an RGB value like that, and now that I've taken a look, it doesn't seem to be covered anywhere on the wiki.
DadOfMrLog
Scratcher
1000+ posts

simple image processing?

amgames wrote:

…wow. Have some magical internet points.
I didn't know about being able to set the pen to an RGB value like that, and now that I've taken a look, it doesn't seem to be covered anywhere on the wiki.
It's not exactly obvious…

I can't recall who first found it (a couple of years ago now, IIRC - the name JTxt comes to mind…), but it's certainly handy we are able to get at the whole colour-space like that (“set pen color+shade” just isn't sufficient).

For a project that provides custom blocks that allow you to continue using the pen in the same kind of way as the built-in Scratch pen blocks (i.e. hue & lightness, aka ‘color’ & ‘shade’), but also with extra blocks for saturation:


Enjoy!

Last edited by DadOfMrLog (July 14, 2014 21:32:09)

MathWizz
Scratcher
100+ posts

simple image processing?

DadOfMrLog wrote:

I can't recall who first found it…
I believe I was the one that found it originally when I discovered colors were stored as numbers in the project's JSON or something like that. Here's the original project project: http://scratch.mit.edu.ezproxyberklee.flo.org/projects/2641383/
gtoal
Scratcher
1000+ posts

simple image processing?

Thanks for all the followup. By the way I think I can do what I wanted if I split any image up into subimages that are vertical columns one pixel wide, then use the ‘painters algorithm’ to paint from the most distant part of the plane towards the front, scaling each slice appropriately. Haven't actually implemented it yet and it would be a lot nicer if I could extract those slices in scratch rather than externally. i'm wondering how fast it would be to read pixels from an image using the touching? block and the RGB hack described above. Would I have to cycle though 2^24 colours at each pixel in order to test each one? Blech!

Answering my own question: I just now found this: http://scratch.mit.edu.ezproxyberklee.flo.org/projects/17713042/ - which makes a scratch-based solution tractable, though far from perfect.

Last edited by gtoal (Aug. 22, 2014 21:54:56)

MrGoldsClass
New Scratcher
2 posts

simple image processing?

Is it possible to scan an image and get each pixels rgb values. I want to do some steganography with my students. Obviously scratch would be great!
drmcw
Scratcher
1000+ posts

simple image processing?

MrGoldsClass wrote:

Is it possible to scan an image and get each pixels rgb values. I want to do some steganography with my students. Obviously scratch would be great!
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/10941245/ will start you off. There are quite a few projects that do what you suggest (not steganography though), although typically at a coarse resolution as getting each pixel would be very slow.

Last edited by drmcw (Dec. 17, 2015 20:20:41)

-Io-
Scratcher
1000+ posts

simple image processing?

MrGoldsClass wrote:

Is it possible to scan an image and get each pixels rgb values. I want to do some steganography with my students. Obviously scratch would be great!
Please avoid posting on old topics, since it clutters things up

If you want to get the exact color you would need to loop through the 16777215 colors a computer can generate for every pixel in the image. That's really slow, and i have tried to do it. I don't recommend it.
There are various projects that can do it like the one drmcw gave. They are not exact though.

Powered by DjangoBB