Hello,
I am trying to take the mean value of a grid of subregions of an image. The images are from a video, hence the using VideoIO
. My question does not actually depend on video-reading functionality
using VideoIO
function analyzeSubregions(filename,rows,cols)
vid = openvideo(filename) # this function is provided by VideoIO package
frames = 2000 # this is the number of frames in the video
data = zeros(length(rows),length(cols),frames) # initialize an empty vector
k = 0
while !eof(vid)
k += 1
frame = floor.(256 .* Float64.(Gray.(read(vid))))
data[:,:,k] = frame[rows,cols]
end
# some processing of "data" ...
end
In the rows
and cols
arguments to this function, I pass ranges, e.g.
analyzeSubregions("example.avi",200:25:300,1000:100:1500)
this creates a matrix of size length(200:25:300) x length(1000:100:1500) x frames
, giving me a “grid” of pixels sampled over the length of the video. So far, so good!
Now, is there a good way to extend this to a grid of sub-arrays?
For example, I would like to use the same grid spacing as above, but with mxn
pixels at each location. so instead of producing an array of 5 x 6
values at the k
’th slice:
5Ă—6 Array{Float64,2}:
0.75848 0.689624 0.759477 0.13272 0.071992 0.922893
0.499832 0.739883 0.676422 0.224262 0.13593 0.941888
0.641937 0.842677 0.624592 0.834348 0.0732766 0.17342
0.177902 0.128434 0.176731 0.85235 0.533129 0.886172
0.67728 0.450755 0.92391 0.317936 0.286406 0.330416
I would like to get something like this at the k
’th slice
5Ă—6 Array{??,2}:
[m x n] [m x n] [m x n] [m x n] [m x n] [m x n]
[m x n] [m x n] [m x n] [m x n] [m x n] [m x n]
[m x n] [m x n] [m x n] [m x n] [m x n] [m x n]
[m x n] [m x n] [m x n] [m x n] [m x n] [m x n]
[m x n] [m x n] [m x n] [m x n] [m x n] [m x n]
Of course, m
and n
would both have to be sufficiently small integers, say, between 2 and 5.
One more thing – I am not actually interested in the entire sub-arrays of size m x n
– I’m actually only interested in the mean value of each sub-array.
- Is there a good, Julia-idiomatic way of extracting a grid of sub-arrays of pixels at the
k
’th slice, similar to how I extract a grid of pixel values? How would I initialize thedata
array in this case? - Further, I need to take the mean of each of those arrays of pixels – so is there a way to extract the mean of the above without needing to allocate an array of arrays?
Thanks for any advice you can offer!