I am developing an interface to visualize 3D images. In this way, the user can select the "slice" (sagittal, coronal or transverse) and progress in volume in changing slice's "index".
I used a slider to change slice's index and also used the callback WindowScrollWheelFcn. For this second process, I used the CurrentPoint on my image plot handle to test if mouse is over the image…. and the problem is here ! …
Take exemple with a data's dimension as 256x256x180. When I plot the 2D slice's image, using imagesc, with a no-square dimension like 256×180, the image is correctly plotted, BUT, it wiil appear my plot "area" as dimension 180×256. This difference between image area and plot area is detected using the WindowScrollWheelFcn and priting the mouse position.
This problem makes that a part of image is not considered inside the image, but a part next to the image it's like inside the image (detected by WindowScrollWheelFcn).
Here some pieces of code:
%%extract 2D image form 3D volume
function update_image(self) self.image = []; if (isempty(self.data) || self.index <= 0) return; end [w, h, d] = size(self.data); switch self.slice case 1 idx = min(self.index, w); self.image = flipud(squeeze(self.data(idx , : , :))'); case 2 idx = min(self.index, h); self.image = flipud(squeeze(self.data(: , idx , :))'); case 3 idx = min(self.index, d); self.image = squeeze(self.data(: , : , idx)); end end %%update plot with image 2D
function update_viewer(self) if (isempty(self.image)) return; end axes(self.gui_axes); old_w = 0; old_h = 0; if (~isempty(self.image_h)) [old_w, old_h] = size(get(self.image_h, 'CData')); end [new_w, new_h] = size(self.image); if (old_w ~= new_w || old_h ~= new_h) self.image_h = imagesc(self.image, self.clims); colormap gray; axis off; axis image; title(self.gui_title); else set(self.image_h, 'CData', self.image); end end
And to get the mouse position :
function [position] = getMousePosition(self) p = get(self.gui_axes, 'CurrentPoint'); position = p(1, 1:2); end
Thanks advence for your help
Best Answer