Rendering fine detail when plotting Fractal sets MATLAB - matlab

I'm trying to analyse the area of a self-similar set in MATLAB. The full image is shown on the LHS below. When zooming in, one can see that MATLAB only renders the image to the scale shown in the centre image. On the RHS below is the resolution when I zoom in on the Matlab figure rather than the printed bitmap - it shows this detail that I want to render, but is not rendered when I print the figure.
I've made the plot with the viscircles function. As a side note, I'd also like to fill in the circles.
I'm using print to save save the plot as a bitmap. I've tried:
Increasing the resolution of the file I'm saving with print, but that doesn't appear to render the image in more detail but merely save the resolution-limited image with more pixels.
Increasing the size of the figure on the screen in the hope of trying to make it render the whole thing. I can't seem to make the image bigger than my monitor. Would suppressing the output of the image help?
A different approach: taking the coordinates that I was passing to viscircles and then drawing circles around them without using a MATLAB plot function. This required a loop for the 10^6 particles in my simulation and was very slow whereas the viscircles approach only took a day - I think it does plot all circles at once.

Related

Export image at full resolution with axes in MATLAB

I am trying to save a large image (1641x6139) at full resolution with MATLAB with axes. Doing this without axes is easy using the imwrite command. To plot the image with axes, I write:
image(x,y,my_image);
Because the image is very large, MATLAB automatically reduces the resolution of the image. The window size would have to be significantly larger than the screen to display the entire image at full resolution. I have tried a couple different approaches to exporting the figure and each runs into the same problem: the image is pixelated at a coarser resolution than the original image. The problem is not that the new image has fewer pixels; instead, neighboring pixels have been assigned the same value, creating the appearance of coarser-scale pixelation.
For example, where H is the figure handle, I tried:
set(H, 'PaperPosition', [0, 0, width , height ])
print -dpng -r500 my_filename
Increasing width, height, or resolution all had the effect of increasing the number of pixels in the image, but the apparent pixelation is unchanged.
I also tried using the function export_fig, which seems to be designed for this type of problem, claiming to export figures with contained images in their native resolution. The resulting image appears to have the correct number of pixels, but as before the problem is that neighboring pixels have the same value, creating the appearance of coarser pixelation absent from the original image. The code I used is:
export_fig(my_filename,'-a1','-native')
Here are a couple images showing roughly the same zoomed in portion of my image:
The first is the original image and the second is the image resulting from export_fig. The second looks pixelated, although again note that each image contains roughly the same number of actual pixels.
Any advice/solutions would be much appreciated! This problem has been much more frustrating than I expected.
I figured out a simple solution. First, I create a blank image of the correct size, add the axes, and then use export_fig to generate an image of the axes. Then, I write my full-resolution image into the image matrix, and save the resulting image using imwrite.

Saving Figure as High Resolution or Lossless Image that can be Zoomed in without Pixelation

I have a big plot in MATLAB (4095 points total) and I want to export this figure as a high res image which can be zoomed in just like the original figure can be zoomed in. Below I attached two images, one is full size plot and the second one was exported separately by zooming in the figure and then exporting. 1st image gets pixelated (obviously) when I zoom in. So my question is if it is possible to export the figure as an image (any format but .fig) that can be zoomed in for more granular detail.
You need to save the figure using a vector format, such as pdf, ps or eps.
For example: try
plot(sin(0:.001:2*pi)) %// example graph
The resulting figure is:
Then print to pdf:
print -dpdf example %// Or change -dpdf to -deps, -depsc, -dps, -dpsc
Now open the generated file, example.pdf. You can zoom on it and you won't see it pixelated. Here's an example of the top of the sinusoid at 6400% zoom.

Problems in implementing the integral image in MATLAB

I tried to implement the integral image in MATLAB by the following:
im = imread('image.jpg');
ii_im = cumsum(cumsum(double(im)')');
im is the original image and ii_im is the integral image.
The problem here is the value in ii_im flows out of the 0 to 255 range.
When using imshow(ii_im), I always get a very bright image which I am not sure is the correct result. Am I correct here?
You're implementing the integral image calculations right, but I don't understand why you would want to visualize it - especially since the sums will go beyond any normal integer range. This is expected as you are performing a summation of intensities bounded by larger and larger rectangular neighbourhoods as you move to the bottom right of the image. It is inevitable that you will get large numbers towards the bottom right. Also, you will obviously get a white image when trying to show this image because most of the values will go beyond 255, which is visualized as white.
If I can add something, one small optimization I have is to get rid of the transposing and use cumsum to specify the dimension you want to work on. Specifically, you can do this:
ii_im = cumsum(cumsum(double(im), 1), 2);
It doesn't matter what direction you specify first (2 then 1, or 1 then 2). The summation of all pixels within each bounded area, as long as you specify all directions to operate on, should be the same.
Back to your question for display, if you really, really, really really... I mean really want to, you can normalize the contrast by doing:
imshow(ii_im, []);
However, what you should expect is a gradient image which starts to be dark from the top, then becomes brighter when you get to the bottom right of the image. Remember, each point in the integral image calculates the total summation of pixel intensities bounded by the top left corner of the image to this point, thus forming a rectangle of intensities you need to sum over. Therefore, as we move further down and to the right of the integral image, the total summation should increase.
With the cameraman.tif image, this is the original image, as well as it's integral image visualized using the above command:
Either way, there is absolutely no reason why you would want to visualize it. You would use this directly with whatever application requires it (adaptive thresholding, Viola-Jones detector, etc.)
Another option could be applying a log operation for each value in the integral image. Something like:
imshow(log(1 + ii_im), []);
However, this will make most of the pixels have the same contrast and this is probably not useful. This is what I get with cameraman.tif:
The moral of this story is that you need some sort of contrast normalization so that you can fit all of the values in your integral image within the confines of the data type that is used to display the image on the screen using imshow.

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.

How do I overlap image with a graph in MATLAB?

I want to write a software that reads the satellite data from a text file and plots graph for different parameters of the oceans. The idea came from Oceonographic Data View(ODV).
My problem is plotting a graph on an image of the Indian ocean, where the image must be overlapped with the graph. Also, on zooming the area, the image with the graph could be zoomed.
How can I do this?
To load and display images, the Displaying Bit-Mapped Images tutorial from MathWorks may not be a bad place to start.
To overlay plots on the image, using hold on followed by plot should work.
An important part will be to have a sensible metric when displaying your image that allows you to place your overlays accurately. In the example below, notice the first and second arguments to image that define this; you could replace it by say linspace(0,1,size(X,1)) if you wanted it scaled between 0 and 1 instead of between 1 and 480 as below.
load mandrill
image(1:480,1:500,X) % display image
colormap(map)
hold on % prevent subsequent plot commands from destroying the image
plot([1 480],[100 100],'w','LineWidth',2) % plot an overlay line