How to used linspace matlab function to get the and the y of all pixels in image? -


i have image of 200x200 * 3, , should find x , y of each pixel of image using linspace matlab function. have used mesh grid function following code:

ny=200; % # pixels in y direction  nx=200; % # pixels in x direction  resolution=1; % size of pixel  img=rand(ny,nx,3); % random image  y=(img(1:ny))*resolution-resolution/2;  x=(img(1:nx))*resolution-resolution/2;  [x,y]=meshgrid(x,y);  

but supervisor told me use function linspace , cannot understand how.can me please

the reason can think of supervisor wants use linspace creating x , y vector inputs meshgrid. linspace alone not sufficient generate of pixel coordinates, you'll have use meshgrid, ndgrid, repelem or repmat.

the 1 advantage linspace has on doing 1:resolution:ny linspace ensures endpoints appear in range. example, if do

>> 1:.37:4 ans =     1.0000    1.3700    1.7400    2.1100    2.4800    2.8500    3.2200    3.5900    3.9600 

you don't 4 last point. however, if use linspace:

>> linspace(1,4,9) ans =    1.0000   1.3750   1.7500   2.1250   2.5000   2.8750   3.2500   3.6250   4.0000 

the spacing automatically adjusted make last element 4.

so assuming resolution multiplier number of points want, 2 want 401 evenly spaced points , 1/2 want 101 points, code this:

x_points = linspace(1, nx, nx*resolution+1); y_points = linspace(1, ny, ny*resolution+1); 

(i'm still not sure resolution/2 part supposed do, we'll need clarify that.)

then pass meshgrid:

[x,y] = meshgrid(x_points, y_points); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -