#Putting a grid on an image

1 messages · Page 1 of 1 (latest)

obtuse gulch
#

Is there a way to put a grid on an image?

Let's imagien I have a pixel art image in 128px by 256px.

Is there a way to basiaclly draw line vertically and horizentally on it for every 1 or x pixels on it to make a grid.

#

Like this

shell jasper
#

tikz/pgf will do this nicely

#

made especially easier with foreach loops!

obtuse gulch
#

ah so I have to do it manually

shell jasper
#

oh if you want an example:

gusty oarBOT
#
\begin{tikzpicture}
[
        scale=0.7
    ]
        \foreach \x in {0,0.25,...,10}{%
            \draw (\x, 0) --(\x, 10);
            \draw (0, \x) -- (10, \x);
        }
\end{tikzpicture}
shell jasper
#

you can also make use of axis environment but you will still need to figure out the intervals etc

#

arbitrary placements of shapes is not a thing in TikZ I'm afraid, this isn't Paint

obtuse gulch
#

Nah, I jsut need the lines

#

But I need TikZ to understand teh length and width of teh image if I'm going to do that

#

and some how place that on top of the image and scale it

#

like usually I use width=\line width for images so teh size can change

shell jasper
#
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.9\textwidth]{Leo}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
    \end{scope}
\end{tikzpicture}
gusty oarBOT
shell jasper
#

Something like this will work

obtuse gulch
#

ey!

shell jasper
#

and yes that's me

obtuse gulch
#

Nice galsses

#

🤔 Also weir dquestion, not relaly related to thsi specificly

#

How doe slatex handel upscalling an image?

shell jasper
#

In Layman-terms or in tech jargon?

obtuse gulch
#

Liek if I throw a pixel art at it the blow it up to cover teh entire screen will it stay pixelated or will it be blury?

#

if it is blkury then... is tehre a way to make it not do that?

#

^ thsi isn't really a deal breaker, I can just upscale it in a photo editor if it can't

#

Aside form that, thansk for the info

shell jasper
#

I think it's just plain stretching

#

which will make low-res images blurry indeed

obtuse gulch
#

🤔 crab

#

Well what you just showed me might be able to fix that if I can ready individual pixel's RPG values which would make a very heavy proccess

shell jasper
#

might not be so bad... this is a 128 x 128

obtuse gulch
#

This doesn't look blury

#

the grid seems to be in the wrong place but the image doesn't seem to be blury

#

This is teh type of problem I'm talking baout

#

Which your image doesn't seem to suffer from

shell jasper
#

Yeah..

#

I have another suggestion

#

Since there's only two colours (or one) in the art, we can just map the image with 0s and 1s using python

and then render the art using the mapped grid

obtuse gulch
#

🤨 LaTeX can read Python?

#

Alos my question is more general, I just happen to have that image at hand

shell jasper
#

just need the numpy array (or equivalent) and then change the [] to braces and then we can just render it using for loops

#

more colours would just mean added layer of mapping which number corresponds to which colour

#

which is still quite easy to automate

obtuse gulch
#

🤔 ye I can see a 6 layer deep array do teh job.

#

for a full RGBA image

shell jasper
#

colour definition can be done in LaTeX though, but you could fetch the value from the array and define it on-the-fly too (which would make it really slow imo)

obtuse gulch
#

Ye would be just manually making upscalling algorithems in LaTeX

fringe reefBOT
#

@obtuse gulch has earned the Members role!

obtuse gulch
#

Thanks for the info man

shell jasper
#

Let me make a quick demonstration of what I meant

#

because it genuinely sounds quite fun

obtuse gulch
#

🤣 Guess I'm not the only one with mad ideas

shell jasper
#
\def\pixels{%
    {2,1,9,9,9,4,3,2,1,0},
    {3,9,8,7,8,9,4,9,2,1},
    {9,8,5,6,7,8,9,8,9,2},
    {8,7,6,7,8,9,6,7,8,9},
    {9,8,9,9,9,6,5,6,7,8}}
\colorlet{pix 0}{black}
\colorlet{pix 1}{red}
\colorlet{pix 2}{green}
\colorlet{pix 3}{yellow}
\colorlet{pix 4}{blue}
\colorlet{pix 5}{yellow}
\colorlet{pix 6}{cyan}
\colorlet{pix 7}{brightblack}
\colorlet{pix 8}{brightgreen}
\colorlet{pix 9}{white}

\begin{tikzpicture}
  \foreach \line [count=\y] in \pixels {
    \foreach \pix [count=\x] in \line {
      \draw[fill=pix \pix] (\x,-\y) rectangle +(1,1);
    }
  }
\end{tikzpicture}
#

Aye

gusty oarBOT
shell jasper
#

The grid is actually from AOC 2021 Day 9 challenge

obtuse gulch
#

hmmm I need to learn how to use this TikZ guy

shell jasper
#

i got carried away...

sharp summit