How can I extract several sets of pixel coordinates (u, v) from an image and store them in a matrix? - matlab

For example, if I were to use the following code for a photo in my MATLAB path:
imtool('Vision.bmp')
the following figure would load:
MATLAB Image with Pixel Coordinates in Bottom Left Corner
Based on where I hover my mouse on this image, the pixel coordinates in the bottom left corner change. I want to be able to extract the coordinates from this image and store them in a matrix, so that later on I can extract the same data - from the image I specified - using this newly created matrix.
Fair warning, I've just started to learn to code.

Related

Crop an image using multiple coordinates in Matlab

I used the "imfreehand" to crop an irregular shape and save its positions into a variable. This position variable is a 85*2 double matrix (85 points, X and Y coordinates). Now, I want to use the same position to crop another image (different layer of the image, but the location of the objects is the same). The functions I can find all requires rectangle positions (X1,X2,Y1,Y2). In my situation, I have 82 different (X,Y) coordinates, how can I use the position information to crop a new image?
From what I understand, you want to take the coordinates created by imfreehand(...) to create a cropable object on another image. You can use the function impoly(hparent,position) for this purpose.
The MathWorks page provides an example to guide you on its usage.

Incorrect pixel value from data cursor on Matlab

When I open a Dicom image on Matlab (R2014b) and place the data cursor on a specific set of coordinates, I obtain an "index" (or pixel value) that does not match the same set of coordinates on the image's matrix (T).
>> figure, imshow(T);
See below on attached image.
Any idea why this is happening?
When using images, the data cursor tool with MATLAB's figure and its various ilk assume that X and Y are the column (horizontal) and row (vertical) coordinates respectively. In the variable inspector (the left part of your figure), these are reversed.
Be careful when using the data cursor on images. See this post by MathWorks on more details regarding interactive display of data: http://www.mathworks.com/help/matlab/creating_plots/data-cursor-displaying-data-values-interactively.html

Mapping Depth onto RGB Kinect using MATLAB

I am trying to map the Depth map onto the RGB image on the Kinec using MATLAB.
So here are the steps that I took:
(1) Obtain the images using a C++ program.
(2) Using the depth value from each pixel on MATLAB, I was able to obtain the XYZ distances of all the pixels in mm.
(3) Then using some equations, I was able to obtain the XY pixel coordinates of those depth pixels on the RGB image.
So I am left with a huge cell containing all the locations of the depth map w.r.t the color image.
So my question is now if I want to overlay the depth image on the color image, how can I do that?
Can anyone help me?
Thanks;

Matlab: Put an image ON TOP of a plot, after the data has been plotted

I have searched the internet for a solution to the question above but have had no luck up to now. I have been producing a number of 2D plots where the origin of (0,0 point) is represented by an image. I have made these by plotting the data on an image, where the image is all white apart from the desired symbol at the center point (so I can reshape it as needed). I then move the axis so they cross at the center point. This all works fine, but I now have to create a number of plots using ‘fill’ to place two shaded areas on the plot that overlap in the center. This causes the symbol to be difficult to see even using ‘alpha’.
I therefore have two options to get the desired effect, both requiring me to put an image on top of the figure after the data is plotted. These options are:
1) I place the image on top of the plot and apply alpha to it (May not look very good as it will mute the plot).
2) The better option would be to crop the image around the symbol and then position it on top of the plot so the image center is at the origin (I have no idea how to position the image this way).
Both methods need the image to be placed on top of the plot after the data is plotted. I have tried 'hold on' and calling 'figure(imagesc(Image))' neither work. I have Matlab 2012b but no toolboxes (so cannot use subimage etc.)
Thanks for any help you can give
You can set the transparency of individual pixels of an image using the 'AlphaData' option. So, you can plot the overlay as follows:
% plot your data normally
...
hold on
% assuming the overlay is a 11x11 image
image(-5:5,-5:5,image_matrix,'AlphaData',alpha_matrix);
image_matrix would obviously be the matrix with your image data stored in it, while alpha_matrix would be a matrix of the same size as image_matrix. Every pixel you want to show would have a value of 1, every pixel you want to hide (the white pixels) would be 0.

Obtain pixel values from an image at the mouse position

I am trying to obtain the pixel values as and when I move my mouse cursor in Maltab .Can I use g-input function in Matlab? I am not getting how to proceed. All the pixel values are doubles.
Does impixelinfo do what you need? This requires Image Processing Toolbox.
Alternatively, can you just use a Data Cursor? For example, type image to display a default image. Then in the figure toolbar, click the Data Cursor button (looks like a little yellow square and a blue line, with a black crosshair). Finally click on a pixel in the image to display X and Y coordinates, and RGB values of the pixel. You can pick the data cursor up with the mouse and move it around to display other pixels.