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
Related
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.
I have a segmented image. i need to verify the intensity variation of the ellipse like structure present in the image. I need to check whether that ellipse is homogeneously white
original image
ellipse like structure is inside the rectangle
my segmented image is
i want to compare the original image (which is homogeneous white) with the segmented region.
regionprops is perfect for this sort of task. You can pass it your segmented binary image, and your original image to retrieve a list of the pixels in each region (presuming each region is not connected, as shown in your sample image). These will be in the form of a n x 1 vector for each region, returned as a struct array.
stats = regionprops(BW, I, 'PixelValues');
(You may want to retrieve other values returned by regionprops, like BoundingBox or Centroid, to help identify which set of pixels belongs to which region more easily. Consult the documentation to see what options are available.).
You can then define some statistical function to show the variation within each region, for example, to calculate the variance and standard deviation for each:
for n = 1:length(stats)
stats(n).var = var(stats(n).PixelValues);
stats(n).std = std(stats(n).PixelValues);
end
If you have some other specific definition of "intensity variation" in mind, then you need to develop some function that calculates it, then just call that instead of a built in like var or std.
I am trying to implement a tracking program using the Mean-Shift algorithm in Matlab. The idea is that, given the first frame of one video, the user can click on top of any object he wants and the program will track it all through the video sequence. I have already implemented and working the tracking part, but I am having problems giving the user the possibility to click on top of the image to select the initial pixel for the tracking algorithm.
I have thought about input function, but I don't know how to make it work. How can I display an image and click on top of a pixel and get its coordinates [x,y] to initialize the program?
You could use ginput (Graphical input from mouse or cursor)
Read any image and show them using imread and imshow
h = imread('hestain.png'); % any input image
imshow(h);
Get the coordinates using ginput, where the input argument corresponds to the number of user clicks recorded.
[x,y] = ginput(1); % getting coordinates from user
To obtain the pixel value, we need to pass the coordinates as indices of the image. To do this, the output arguments from the ginput which are double by default, must be converted to unsigned integers.
Also, x and y represents horizontal and vertical by default. But matlab syntax takes first dimension as rows (number of horizontal lines calculated vertically). Hence y value is passed as first dimension. Similarly x value as second dimension.
pixelValue = h(uint8(y),uint8(x)); % using coordinates as indices
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.
I want to select a pixel in an image using floating-point numbers as indexes. The Matlab documentation says that this is possible using "spatial coordinates". However, it doesn't provide any clues on how to do it. How can I select a pixel from an image using floating-point indexes ("spatial coordinates")?
Suppose that I have the following code:
i = imread('pout.tif')
get_pixel_by_spatial_coords(i, 1.5, 3.63)
What's the real name of the function get_pixel_by_spatial_coords?
I think the linked article on spatial coordinates was only describing the coordinate systems used by various image plotting routines.
Your your purpose, simply round the number. Depending on the context, use one of:
i(round(1.5), round(3.63))
i(floor(1.5), floor(3.63))
i(ceil(1.5), ceil(3.63) )
I believe you're looking for ginput:
ginput raises crosshairs in the current axes to for you to identify points in the figure, positioning the cursor with the mouse. The figure must have focus before ginput can receive input. If it has no axes, one is created upon the first click or keypress.