# Subsampling an image by a factor

Hi!

I am trying to subsample an image only in the vertical direction by a factor t (value is a geometric progression with common ratio sqrt(2)).

Is there any built-in function to subsample images? I was thinking of restrict() but since t is variable and irrational I am not sure if that is a good idea.

Thanks!

Hi PetrKryslUCSD!

Yes, I am using JuliaImages but can’t find a relevant function. So am thinking of converting to a matrix and then the subsampling.

Can’t you do it just by indexing into the images directly? Like `img[t, :]`. It’s not clear exactly what `t` is, though. Is it a vector, a function or what?

1 Like

Then perhaps Interpolations.jl?

Can you clarify what you mean by subsampling? To me, that means selecting a subset of the currently available samples. But maybe you are talking about re-sampling, using e.g. interpolation or smoothing?

Hi, t is a variable inside a loop. Initially t=1 and in further iterations of the loop it gets multiplied by sqrt(2).

I can try indexing into the image. The issue is my code is already at O(n^3) complexity. I was wondering if there is already an inbuilt function which won’t affect the complexity too much.

I mean subsampling=downsampling, i.e. taking the tth rows of pixels and ignoring the intermediate ones in case of vertical downsampling.

Thanks!

Thanks PetrKryslUCSD!

I am checking that.

Hi yakir12!

I was actually thinking the same. But have a confusion. For eg., in Matlab the image resize function uses weights on the surrounding pixels while resizing the image. But according to the paper I am trying to implement, I just need to skip the intermediate rows of pixels and consider only those rows which are multiples of t, and there are no weight involved. So I am not sure if Julia uses weights while discaring pixels to resize the image.

`imresize` interpolates between pixels when downscaling. You might just want to index into the image?

`sqrt_restrict(img, i) = img[1:round(Int,sqrt(2)^i):end, :]`

1 Like

@stillyslalom

Thanks a lot!