IMCROP, zoom in, matlab - matlab

I am using
[X,Y,I2,rect] = imcrop(…)
function to get my sub-image.
1- I want first to zoom in my image and then crop my image. How it will work?
Using imtool i can first zoom in and then crop my image but i can export store rect coordinates.
regards,

This is supported out of the box: after you call IMCROP, a figure opens up with the image displayed. From the toolbar, use the pan/zoom tools as usual, once done disable them and you would be back to the mode where you specify the draggable rectangle. Make your selection and double-click it to accept.
Here is an example:
I = imread('coins.png');
[I2,rect] = imcrop(I);
figure, imshow(I2)

Assuming you want to produce a new zoomed/cropped image, you can use imresize to enlarge the image before calling imcrop:
B = imresize(A, scale)
If instead you have the image displayed in Matlab and you want to zoom in on the figure programmatically, then you can use the zoom function:
zoom(factor)
See the documentation for details:
imresize API: http://www.mathworks.com/help/toolbox/images/ref/imresize.html
zoom API: http://www.mathworks.com/help/techdoc/ref/zoom.html

Related

Adding Color Maps to images in MATLAB

This is a fairly entry-level question but I could not find the answer to it here on SO or on Mathworks help.
I want to add a color bar to an image I am loading and then save the image along with the created color bar.
The result I am looking for is like figure 1 on this page except that there is an image instead of the plot and the color bar shows the range of intensities in the image.
The page made me think that running
colorbar(<trarget matrix>);
Would do the trick but that throws an error when I try to apply it to an image.
So my question is, how do I make a color bar for my image and once made what would be a good way to concatenate the two for saving.
I am loading the image using the following snippet
IMGpath = 'barbaraSmall.png';
im = imread(IMGpath, 'png');
%
%colorbar(im); >>Throws an error
imshow(im);
imwrite(im, 'barabara_withMAP.png', 'png');
The syntax that you're using is colorbar(target). According to the documentation,
target is:
"Target for the colorbar, specified as an Axes object, a PolarAxes object, or a graphics object that has a ColorbarVisible property".
You're inputting an image matrix (im) as target which is none of the above mentioned objects. You can simply just enter:
colorbar;
or if you want to give an axes' handle then:
colorbar(gca);
You can save the result using saveas.
saveas(gca, 'barabara_withMAP.png')

Matlab GUI Scrollbar Available

Does anyone know if I can make a horizontal and vertical scroll bar in a MATLAB GUI (not a list box)? Depending on the resolution of a computer it may or may not show all of the figure so I need to be able to scroll (horizontally in my case). How to do that?
This will create a figure with a horizontal scrollbar:
figure
plot(1:3);
b = uicontrol('Parent',gcf,...
'Style','slider',...
'Units','Normalize',...
'Position',[0,0,1,0.05],...
'min',0, 'max',1,...
'Value', 0);
However, if I were you, I would rather make sure the figure fits the screen and allow the user to zoom. Having a graph larger than screensize deprives the user from observing the entire graph at once.
You could
a) let matlab choose default figure size of the figure. Then the user can fullscreen if desired, or b)
screensize = get(groot,'Screensize');
figure('Position',screensize)
I hope this helps.

remove some top, down rows and right, and left some columns of jpg image border using matlab

I have RGB museum JPG Images. most of them have image footnotes on one or more sides, and I'd like to remove them. I do that manually using paint software. now I applied the following matlab code to remove the image footnotes automatically. I get a good result for some images but for others it not remove any border. Please, can any one help me by update this code to apply it for all images?
'rgbIm = im2double(imread('A3.JPG'));
hsv=rgb2hsv(rgbIm);
m = hsv(:,:,2);
foreground = m > 0.06; % value of background
foreground = bwareaopen(foreground, 1000); % or whatever.
labeledImage = bwlabel(foreground);
measurements = regionprops(labeledImage, 'BoundingBox');
ww = measurements.BoundingBox;
croppedImage = imcrop(rgbImage, ww);'
In order to remove the boundaries you could use "imclearborder", where it checks for labelled components at boundaries and clears them. Caution! if the ROI touches the boundary, it may remove. To avoid such instance you can use "imerode" with desired "strel" -( a line or disc) before clearing the borders. The accuracy or generalizing the method to work for all images depends entirely on "threshold" which separates the foreground and background.
More generic method could be - try to extract the properties of footnotes. For instance, If they are just some texts, you can easily remove them by using a edge detection and morphology opening with line structuring element along the cols. (basic property for text detection)
Hope it helps.
I could give you a clear idea or method if you upload the image.

matlab preview of live video and a circle reference at the centre of frame

I have used matlab's preview window in the following syntax:
figure('Name', 'My Custom Preview Window');uicontrol('String', 'Close', 'Callback', 'close(gcf)');
I am able to successfully get the video stream. Now I want to have a small circle as a region of interest to return the average pixel value within this circle. I want this to be stored and named after a click of a button and recalled later for the further processing.
Could anyone guide me where I can start with?
Please note I dont want user to define ROI instead its always fixed as a small circle at the centre of field view. Whatever the colours comes within the circle I want mean values to be calculated and stored as a reference.
Ps: I am not sure I am correct in calling ROI its simple circle in the field view
You might want to try using a Matlab gui instead of a simple figure. Then you could try something like this.

MatLab: displaying figures side by side

As when you use subplot to display plots side by side in the same window, I would like a similar function that can do the same for multiple figures. This works:
subplot(2,2,1)
and I am looking for something like this:
subfigure(2,2,1)
Does a build-in function with this advantage exist?
You could write one such function yourself. The idea is to get the screen size:
get(0,'ScreenSize')
then divide it up into sub-regions according to the input parameters. You would also need to account for margins in-between.
Another idea:
create an invisible figure (preferably same aspect ratio as the screen)
call subplot inside it
capture the position of the created axis
delete figure
scale the position captured to fit the screen size, and use it to create the actual figures.