Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9939 > unrolled thread

Drawing on an image in Mathematica

Started byJulian Francis <julian.w.francis@gmail.com>
First post2012-05-04 02:25 +0000
Last post2012-05-06 07:24 +0000
Articles 5 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Drawing on an image in Mathematica Julian Francis <julian.w.francis@gmail.com> - 2012-05-04 02:25 +0000
    Re: Drawing on an image in Mathematica JUN <noeckel@gmail.com> - 2012-05-04 10:28 +0000
      Re: Drawing on an image in Mathematica Julian Francis <julian.w.francis@gmail.com> - 2012-05-06 07:23 +0000
        Re: Drawing on an image in Mathematica JUN <noeckel@gmail.com> - 2012-05-07 00:32 +0000
      Re: Drawing on an image in Mathematica JUN <noeckel@gmail.com> - 2012-05-06 07:24 +0000

#9939 — Drawing on an image in Mathematica

FromJulian Francis <julian.w.francis@gmail.com>
Date2012-05-04 02:25 +0000
SubjectDrawing on an image in Mathematica
Message-ID<jnven4$8ee$1@smc.vnet.net>
Dear all,

I have a binary image in which I'd like to use the mouse to draw
(freehand) on top of the image, and use this in Mathematica.

Presently, I can import the image into a painting program, use its
sketching facilities, then cut and paste into Mathematica. I can
extract the matrix if I wish by using ImageData.

Is there a way of drawing on the image directly in Mathematica to save
me cutting and pasting between programs?

I've worked out how to create a graphic and draw into it using the
Mathematica graphics drwaing tools, but my problem is either the
graphic is far too large, or if I shrink it down
(I want to work on matrices 16x16), the resulting picture is far too
small. I want to draw into a matrix 16x16, but it be large enough for
me to see easily.

Thanks,
Julian.

[toc] | [next] | [standalone]


#9954

FromJUN <noeckel@gmail.com>
Date2012-05-04 10:28 +0000
Message-ID<jo0avr$cb2$1@smc.vnet.net>
In reply to#9939
On Thursday, May 3, 2012 7:25:40 PM UTC-7, Julian Francis wrote:
> Dear all,
> 
> I have a binary image in which I'd like to use the mouse to draw
> (freehand) on top of the image, and use this in Mathematica.
> 
> Presently, I can import the image into a painting program, use its
> sketching facilities, then cut and paste into Mathematica. I can
> extract the matrix if I wish by using ImageData.
> 
> Is there a way of drawing on the image directly in Mathematica to save
> me cutting and pasting between programs?
> 
> I've worked out how to create a graphic and draw into it using the
> Mathematica graphics drwaing tools, but my problem is either the
> graphic is far too large, or if I shrink it down
> (I want to work on matrices 16x16), the resulting picture is far too
> small. I want to draw into a matrix 16x16, but it be large enough for
> me to see easily.
> 
> Thanks,
> Julian.

The image has to be put into a Graphics box, and you can do that using the Inset command:

im = RandomImage[1, {16, 16}];
Graphics[Inset[im, Automatic, Automatic, Scaled[1]]]

Here I've just used a random image and scaled it to fill the default Graphics width. Now you can double-click on the graphic and press Control-t to get the drawing tools, and they should work as you want.

I think what you want to do after you're done editing is to convert the result back to an image. To do that, you could type:

Rasterize[      , "Image", ImageSize -> 16]

and copy the edited graphic from the previous cell back into the empty space I left in the Rasterize command. The result is again an image of the original dimensions.

Jens

[toc] | [prev] | [next] | [standalone]


#9969

FromJulian Francis <julian.w.francis@gmail.com>
Date2012-05-06 07:23 +0000
Message-ID<jo58tn$2av$1@smc.vnet.net>
In reply to#9954
Hi Jens,

Thanks very much for your reply. I think what you've suggested is
pretty close to what I am looking for.
The only thing is that when you use the drawing tool, it draws a thin
line across the (what is effectively a matrix) picture.

It would be better if it actually filled in the whole pixels.

I realise I'm not explaining myself very well! You know how if you
zoom in using a paint program to a portion of a picture and then draw
on it. You don't get a thin drawing line, because the picture doesn't
have that resolution at that scale. Instead the program alters the
pixels behind the picture which looks like blocks.

I'll try another way of explaining it. Supposing you have a matrix of
16x16 of (black n white). You have it magnified on screen say to
physically take up 256x256 pixels so that you can see it properly. So
each element of the matrix takes up a physical block on screen of
16x16 pixels. If you click on the mouse to draw on the matrix, a whole
screen 16x16 block should change, which corresponds to 1x1 in the
matrix.

I hope that makes sense! It's one of those things that much easier to
demo than explain!

Thanks,
Julian.

On May 4, 11:28 am, JUN <noec...@gmail.com> wrote:
> On Thursday, May 3, 2012 7:25:40 PM UTC-7, Julian Francis wrote:
> > Dear all,
>
> > I have a binary image in which I'd like to use the mouse to draw
> > (freehand) on top of the image, and use this in Mathematica.
>
> > Presently, I can import the image into a painting program, use its
> > sketching facilities, then cut and paste into Mathematica. I can
> > extract the matrix if I wish by using ImageData.
>
> > Is there a way of drawing on the image directly in Mathematica to save
> > me cutting and pasting between programs?
>
> > I've worked out how to create a graphic and draw into it using the
> > Mathematica graphics drwaing tools, but my problem is either the
> > graphic is far too large, or if I shrink it down
> > (I want to work on matrices 16x16), the resulting picture is far too
> > small. I want to draw into a matrix 16x16, but it be large enough for
> > me to see easily.
>
> > Thanks,
> > Julian.
>
> The image has to be put into a Graphics box, and you can do that using th=
e Inset command:
>
> im = RandomImage[1, {16, 16}];
> Graphics[Inset[im, Automatic, Automatic, Scaled[1]]]
>
> Here I've just used a random image and scaled it to fill the default Grap=
hics width. Now you can double-click on the graphic and press Control-t to =
get the drawing tools, and they should work as you want.
>
> I think what you want to do after you're done editing is to convert the r=
esult back to an image. To do that, you could type:
>
> Rasterize[      , "Image", ImageSize -> 16]
>
> and copy the edited graphic from the previous cell back into the empty sp=
ace I left in the Rasterize command. The result is again an image of the or=
iginal dimensions.
>
> Jens

[toc] | [prev] | [next] | [standalone]


#9975

FromJUN <noeckel@gmail.com>
Date2012-05-07 00:32 +0000
Message-ID<jo756f$bst$1@smc.vnet.net>
In reply to#9969
On Sunday, May 6, 2012 12:23:35 AM UTC-7, Julian Francis wrote:
> Hi Jens,
>
> Thanks very much for your reply. I think what you've suggested is
> pretty close to what I am looking for.
> The only thing is that when you use the drawing tool, it draws a thin
> line across the (what is effectively a matrix) picture.
>
> It would be better if it actually filled in the whole pixels.
>
> I realise I'm not explaining myself very well! You know how if you
> zoom in using a paint program to a portion of a picture and then draw
> on it. You don't get a thin drawing line, because the picture doesn't
> have that resolution at that scale. Instead the program alters the
> pixels behind the picture which looks like blocks.
>
> I'll try another way of explaining it. Supposing you have a matrix of
> 16x16 of (black n white). You have it magnified on screen say to
> physically take up 256x256 pixels so that you can see it properly. So
> each element of the matrix takes up a physical block on screen of
> 16x16 pixels. If you click on the mouse to draw on the matrix, a whole
> screen 16x16 block should change, which corresponds to 1x1 in the
> matrix.
>
> I hope that makes sense! It's one of those things that much easier to
> demo than explain!
>
> Thanks,
> Julian.
>
> On May 4, 11:28 am, JUN <noec...@gmail.com> wrote:
> > On Thursday, May 3, 2012 7:25:40 PM UTC-7, Julian Francis wrote:
> > > Dear all,
> >
> > > I have a binary image in which I'd like to use the mouse to draw
> > > (freehand) on top of the image, and use this in Mathematica.
> >
> > > Presently, I can import the image into a painting program, use its
> > > sketching facilities, then cut and paste into Mathematica. I can
> > > extract the matrix if I wish by using ImageData.
> >
> > > Is there a way of drawing on the image directly in Mathematica to sav=
e
> > > me cutting and pasting between programs?
> >
> > > I've worked out how to create a graphic and draw into it using the
> > > Mathematica graphics drwaing tools, but my problem is either the
> > > graphic is far too large, or if I shrink it down
> > > (I want to work on matrices 16x16), the resulting picture is far too
> > > small. I want to draw into a matrix 16x16, but it be large enough for
> > > me to see easily.
> >
> > > Thanks,
> > > Julian.
> >
> > The image has to be put into a Graphics box, and you can do that using =
th=
> e Inset command:
> >
> > im = RandomImage[1, {16, 16}];
> > Graphics[Inset[im, Automatic, Automatic, Scaled[1]]]
> >
> > Here I've just used a random image and scaled it to fill the default Grap
> hics width. Now you can double-click on the graphic and press Control-t to > get the drawing tools, and they should work as you want.
> >
> > I think what you want to do after you're done editing is to convert the r> esult back to an image. To do that, you could type:
> >
> > Rasterize[      , "Image", ImageSize -> 16]
> >
> > and copy the edited graphic from the previous cell back into the empty sp
> ace I left in the Rasterize command. The result is again an image of the or
> iginal dimensions.
> >
> > Jens

So you want to do pixel art, and want to draw with really big pixels. Well, it can be done, but requires writing your own drawing code using Manipulate. With my earlier suggestion, you can at least get closer to what you want by using the largest thickness for the "Stroke" setting in the editing too ls, and then turning off anti-aliasing when you're rasterizing back down to 16x16 pixels. E.g., you'd paste the drawing into this empty slot:

Rasterize[Style[       , Antialiasing -> False], ImageSize -> 16]

The result will look more pixelated, and you can in principle predict while drawing which pixels are going to get colored, because the Rasterize comma nd won't care if you colored in all the rectangles completely - it will fill them in for you as long as the brush covered most of a pixel.

To go all the way and write an interactive pixel drawing program, maybe you can find more help by looking at this link:

http://demonstrations.wolfram.com/DrawingALineOnADigitalDisplay/

Jens

[toc] | [prev] | [next] | [standalone]


#9971

FromJUN <noeckel@gmail.com>
Date2012-05-06 07:24 +0000
Message-ID<jo58vl$2bm$1@smc.vnet.net>
In reply to#9954
On Friday, May 4, 2012 3:28:11 AM UTC-7, JUN wrote:
> On Thursday, May 3, 2012 7:25:40 PM UTC-7, Julian Francis wrote:
> > Dear all,
> >
> > I have a binary image in which I'd like to use the mouse to draw
> > (freehand) on top of the image, and use this in Mathematica.
> >
> > Presently, I can import the image into a painting program, use its
> > sketching facilities, then cut and paste into Mathematica. I can
> > extract the matrix if I wish by using ImageData.
> >
> > Is there a way of drawing on the image directly in Mathematica to save
> > me cutting and pasting between programs?
> >
> > I've worked out how to create a graphic and draw into it using the
> > Mathematica graphics drwaing tools, but my problem is either the
> > graphic is far too large, or if I shrink it down
> > (I want to work on matrices 16x16), the resulting picture is far too
> > small. I want to draw into a matrix 16x16, but it be large enough for
> > me to see easily.
> >
> > Thanks,
> > Julian.
>
> The image has to be put into a Graphics box, and you can do that using the Inset command:
>
> im = RandomImage[1, {16, 16}];
> Graphics[Inset[im, Automatic, Automatic, Scaled[1]]]
>
> Here I've just used a random image and scaled it to fill the default Graphics width. Now you can double-click on the graphic and press Control-t to get the drawing tools, and they should work as you want.
>
> I think what you want to do after you're done editing is to convert the result back to an image. To do that, you could type:
>
> Rasterize[      , "Image", ImageSize -> 16]
>
> and copy the edited graphic from the previous cell back into the empty space I left in the Rasterize command. The result is again an image of the or iginal dimensions.
>
> Jens

Reading this again, I should clarify that you can also edit the image directly if you magnify it by dragging its outline manually, or doing Magnify[im,20] ... the Inset method above isn't the only way, I guess it's just the first thing that came to mind when you mentioned your own approach. 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web