Is there a way to "cut out" a piece of image and use it with the P5.js library?
Example: Lets say I have a image of the size 100x100 but need to get a 10x10 pixel cutout that starts at pixel 50,50
I want to take the resulting 10x10 image and place it anywhere with image(result, X, Y, 10, 10).
Note:
The only thing I could find online similar to this was using mask() but the result is not what I need.
After a deeper look inside, and help from fellow P5ers I figured out that the solution is:
The GET() method from P5.js
https://p5js.org/reference/#/p5/get
The get() method can be used as needed: get(startX, startY, width, height) and returns and image that can be saved or used as needed.
You can also use copy() from p5.
P5 copy() reference
Related
I have an image with many shapes and I need to write some Matlab code which remove all the shapes except the rectangle.. Does it availabe to do it using only with strel,imclose and bwareaopen? if you think yes i will be very happy to hear your opinion.
Image:
If I understood right from your comment, rectangle may have any size. I think this can be asked only if the other shapes have fixed size since you are asked to use strel, imclose and bwareaopen. To briefly explain,
strel function creates a structuring element with given size for rectangle, disk or any other shape on the picture you added.
imclose should be used to connect the similar shapes you give as input(basically the structuring element you should find from the strel function).
bwareaopen will be used to delete the objects which has less than P -given as input- pixels.
So, if the rectangle can be given in any size for this image, the other shapes should stay the same in order to be able to define them with strel function, and connect by using imclose function. In this way, you may connect them all, take inverse, remove using bwareaopen and take inverse once again to end up with rectangle.
I could not think about any other solution, hope it helps!
I have an image with many shapes and I need to write some Matlab code which remove all the shapes except the rectangle.. Does it availabe to do it using only with strel,imclose and bwareaopen? if you think yes i will be very happy to hear your opinion.
Image:
If I understood right from your comment, rectangle may have any size. I think this can be asked only if the other shapes have fixed size since you are asked to use strel, imclose and bwareaopen. To briefly explain,
strel function creates a structuring element with given size for rectangle, disk or any other shape on the picture you added.
imclose should be used to connect the similar shapes you give as input(basically the structuring element you should find from the strel function).
bwareaopen will be used to delete the objects which has less than P -given as input- pixels.
So, if the rectangle can be given in any size for this image, the other shapes should stay the same in order to be able to define them with strel function, and connect by using imclose function. In this way, you may connect them all, take inverse, remove using bwareaopen and take inverse once again to end up with rectangle.
I could not think about any other solution, hope it helps!
I am trying to map my image point by point to 3 dimensional space.
For example, if my original image has intensity of 100 at location X, I want to plot this point in 3D location Y with intensity of 100. I want to repeat this steps for every point/pixel, and get a final image. My biggest problem is that I want to do it point by point.
I appreciate any comments or advice. Thank you.
=======================
p.s.
As I was writing this question, I just came up with an idea. I know how to print 'whole' image into certain location/shape in 3D by using warp() function. Instead of using my whole image as an argument to warp function, if I give one point intensity value and one 3D point as arguments for warp function, and repeat this steps for every image point, will I get a descent looking final image in 3D? If there is a better function to use, please let me know.
Sounds like you are looking for scatter3:
I = imread('cameraman.tif');
[x y]=meshgrid(1:size(I,1), 1:size(I,2));
scatter3(x(:),y(:),I(:),15,I(:),'filled');
axis tight; colormap gray
And this is what you get (after some changes to view point):
PS,
I used a single scatter3 command to plot all the points at once. You may (I have no idea why you would like to do so) do it one by one
figure;
for ii=1:numel(x)
scatter( x(ii), y(ii), I(ii), 15, I(ii), 'filled');
hold on; % need this!
end
axis tight; colormap gray;
basically, i am supposed to create a image with circles and lines... not using plot function.
because the final output is to pop out by imshow().or image().or imagesc()...
and the created image will contiune the color processing.
The simplest way is to draw it as usual, then use getframe to grab an image of the figure.
EDIT: I don't have time for much detail, but look at the following:
line: http://www.mathworks.co.uk/help/techdoc/ref/line.html
circle: http://www.mathworks.com/matlabcentral/fileexchange/2876
axis properties: http://www.mathworks.co.uk/help/techdoc/ref/axes_props.html (You may want to set 'Visible', 'off', 'Position', [0 0 1 1], 'DataAspectRatio', [1 1 1])
getframe: http://www.mathworks.co.uk/help/techdoc/ref/getframe.html
The MATLAB help is really very useful.
If you are trying to draw lines and circles directly on a raster image (matrix of pixels), then check out the Bresenham line-drawing algorithm and its variants for circles.
I am sure you can find existing implementations for them on FEX
Another possibility is to show the image (IMSHOW, IMAGESC, ..), use the plotting functions as usual (PLOT, LINE, ...), then grab the displayed figure as image again using GETFRAME as Nzbuu suggested.
Use the matlab function "rectangle" and specify the 'Curvature" parameter to one. i.e.
rectangle('Position',[0 0 100 100],'Curvature',[1 1])
This is obviously counter intuitive, but in Matlab, rectangle is the function you use to draw ellipses and circles.
Here is the appropriate mathworks doc:
http://www.mathworks.com/help/techdoc/ref/rectangle.html
I have an image and two points,
and I want to read the pixels between these two points,
and resample them into a small 1x40 array.
I'm using EMGU which is a C# wrapper for OpenCV.
thanks,
SW
What you are looking for is Bresenham's line algorithm. It will allow you to get the points in the pixel array that best approximate a straight line. The Wikipedia link also contains psuedo code to get you started.
Emgu CV includes method in the Image class for sampling color along a line called Sample.
Refer to the manual for the definition. Here's the link to Image.Sample in version 2.3.0.
You will still have to re-sample/interpolate the points in array returned from Sample to end up with a 40 element array. Since there are a number of ways to re-sample, I'll suggest you look to other questions for that.
Rotate and crop
I'd first try to do it like this:
calculate rotation matrix with (GetRotationMatrix2D)
warp the image so that this line is horisontal (WarpAffine)
calculate new positions of two of your points (you can use Transform)
get image rectangle of suitable width and 1 px high (GetRectSubPix)
Interpolation here and there may affect the results, but you have to interpolate anyway. You may consider cropping the image before rotation.
Iterate over the 8-connected pixels of the line
Otherwise you may use the line iterator to iterate over the pixels between two points. See documentation for InitLineIterator (Sorry, the link is to the Python version of OpenCV, I've never heard of EMGU). I suppose that in this case you iterate over pixels of a line which was not antialiased. But this should be much faster.
Interpolate manually
Finally, you may convert the image to an array, calculate which elements the line is passing through and subsample and interpolate manually.