I'm trying to create a matrix plot with mathematica. Using ArrayPlot[] I get a very nice figure, apart from the fact that it's surrounded by a white margin. I've got to the root of the problem, in the sense of the following example.
http://img689.imageshack.us/img689/8427/badmargin.png
If I try to export the resulting graphic, it exports the margin also. I want my array content to fill a rectangle of a certain size so that it can be superimposed on another image, but the ArrayPlot function produces margins that interfere.
What do?
QuickEdit: ImageCrop will not work in my case, because a) I want my resulting image to be of a certain size, and b) without specifying how wide margins I want to remove the automatic version may mess with my graph (first row may well be white, for example).
Try PlotRangePadding->0
Apparently my reply was too short, so I'm typing more.
If you set the option Background->None the edges should be transparent. This would work if you were embedding it in another graphic.
Related
I don't know much about image processing so please bear with me if this is not possible to implement.
I have several sets of aerial images of the same area originating from different sources. The pictures have been taken during different seasons, under different lighting conditions etc. Unfortunately some images look patchy and suffer from discolorations or are partially obstructed by clouds or pix-elated, as par example picture1 and picture2
I would like to take as an input several images of the same area and (by some kind of averaging them) produce 1 picture of improved quality. I know some C/C++ so I could use some image processing library.
Can anybody propose any image processing algorithm to achieve it or knows any research done in this field?
I would try with a "color twist" transform, i.e. a 3x3 matrix applied to the RGB components. To implement it, you need to pick color samples in areas that are split by a border, on both sides. You should fing three significantly different reference colors (hence six samples). This will allow you to write the nine linear equations to determine the matrix coefficients.
Then you will correct the altered areas by means of this color twist. As the geometry of these areas is intertwined with the field patches, I don't see a better way than contouring the regions by hand.
In the case of the second picture, the limits of the regions are blurred so that you will need to blur the region mask as well and perform blending.
In any case, don't expect a perfect repair of those problems as the transform might be nonlinear, and completely erasing the edges will be difficult. I also think that colors are so washed out at places that restoring them might create ugly artifacts.
For the sake of illustration, a quick attempt with PhotoShop using manual HLS adjustment (less powerful than color twist).
The first thing I thought of was a kernel matrix of sorts.
Do a first pass of the photo and use an edge detection algorithm to determine the borders between the photos - this should be fairly trivial, however you will need to eliminate any overlap/fading (looks like there's a bit in picture 2), you'll see why in a minute.
Do a second pass right along each border you've detected, and assume that the pixel on either side of the border should be the same color. Determine the difference between the red, green and blue values and average them along the entire length of the line, then divide it by two. The image with the lower red, green or blue value gets this new value added. The one with the higher red, green or blue value gets this value subtracted.
On either side of this line, every pixel should now be the exact same. You can remove one of these rows if you'd like, but if the lines don't run the length of the image this could cause size issues, and the line will likely not be very noticeable.
This could be made far more complicated by generating a filter by passing along this line - I'll leave that to you.
The issue with this could be where there was development/ fall colors etc, this might mess with your algorithm, but there's only one way to find out!
I have the coordinate indicating the start of each letter within a word. I have set the plot function to make a red circle at that coordinate like so:
The problem is that the paper I am adding this image to has a structure of 2 columns per page. And when I add 2 of the above image to the same column, the circles become very small and difficult to notice.
I tried instead of circles to make triangles or pentagrams. I get the same result, they become too small to distinguish.
How can I make this more distinguishable? Especially when its printed in black and white.
You can change the marker size of the markers, and\or overlay two different markers one of the other. For example:
x=1:100;
y=rand(1,100);
plot(x,y); hold on
n=20:20:60;
plot(x(n),y(n),'r+','MarkerSize',30,'LineWidth',2);
plot(x(n),y(n),'ro','MarkerSize',15,'LineWidth',2);
There are many other degrees of freedom you can use to add \ change to this. It is a very basic question that you could have answered yourself if you read the documentation of plot in TMW website.
If I want to draw a text on a control, I can get "a bounding rectangle" first and place it at an appropriate place (using GetTextExtentPoint32 function).
But I also need to know where some baselines are, e.g the two red lines in the picture.
(Their positions are calculated respect to the top of the bounding rectangle.)
I didn't figure a way to get these information. Please help.
The function GetTextMetrics will get you this. Select your font into the DC first, then call GetTextMetrics. The fields tmAscent and tmDescent of the TEXTMETRIC structure are probably the ones you need.
I have two matrices where one is RxCx3 (RGB image) and the other is RxC (labelings). Most of the labels are zero and I would like to paint the non-zero labels on the RGB image. More specifically, I would like to superimpose the figure:
imagesc(labels)
onto the figure:
imshow(rgb)
except the zero values in labels. What is the quickest way to achieve it?
Well here's my interpretation of your problem: You want to superimpose non-zero elements of a matrix onto an image (an example of this might be a heat map).
This page here will give you everything you need regarding the non-zero aspect, but generally you will do something like
find(Labels)
inside a processing section that will then only process those elements of "Labels" > 0. (You can make the expression inside "find" way more complex if your needs change)
Find - Matlab
To actually superimpose the image though (you require labels), you need to make a decision. Physically alter the image to be displayed to show the labels or overlay the labels transparently. The following page has great information on achieving this result:
Overlaying Image in MATLAB
I suspect for your requirements, you'd want to take the transparency route (I would recommend it as well)
i'm working in a project to recognize a bit code from an image like this, where black rectangle represents 0 bit, and white (white space, not visible) 1 bit.
Somebody have any idea to process the image in order to extract this informations? My project is written in java, but any solution is accepted.
thanks all for support.
I'm not an expert in image processing, I try to apply Edge Detection using Canny Edge Detector Implementation, free java implementation find here. I used this complete image [http://img257.imageshack.us/img257/5323/colorimg.png], reduce it (scale factor = 0.4) to have fast processing and this is the result [http://img222.imageshack.us/img222/8255/colorimgout.png]. Now, how i can decode white rectangle with 0 bit value, and no rectangle with 1?
The image have 10 line X 16 columns. I don't use python, but i can try to convert it to Java.
Many thanks to support.
This is recognising good old OMR (optical mark recognition).
The solution varies depending on the quality and consistency of the data you get, so noise is important.
Using an image processing library will clearly help.
Simple case: No skew in the image and no stretch or shrinkage
Create a horizontal and vertical profile of the image. i.e. sum up values in all columns and all rows and store in arrays. for an image of MxN (width x height) you will have M cells in horizontal profile and N cells in vertical profile.
Use a thresholding to find out which cells are white (empty) and which are black. This assumes you will get at least a couple of entries in each row or column. So black cells will define a location of interest (where you will expect the marks).
Based on this, you can define in lozenges in the form and you get coordinates of lozenges (rectangles where you have marks) and then you just add up pixel values in each lozenge and based on the number, you can define if it has mark or not.
Case 2: Skew (slant in the image)
Use fourier (FFT) to find the slant value and then transform it.
Case 3: Stretch or shrink
Pretty much the same as 1 but noise is higher and reliability less.
Aliostad has made some good comments.
This is OMR and you will find it much easier to get good consistent results with a good image processing library. www.leptonica.com is a free open source 'C' library that would be a very good place to start. It could process the skew and thresholding tasks for you. Thresholding to B/W would be a good start.
Another option would be IEvolution - http://www.hi-components.com/nievolution.asp for .NET.
To be successful you will need some type of reference / registration marks to allow for skew and stretch especially if you are using document scanning or capturing from a camera image.
I am not familiar with Java, but in Python, you can use the imaging library to open the image. Then load the height and the widths, and segment the image into a grid accordingly, by Height/Rows and Width/Cols. Then, just look for black pixels in those regions, or whatever color PIL registers that black to be. This obviously relies on the grid like nature of the data.
Edit:
Doing Edge Detection may also be Fruitful. First apply an edge detection method like something from wikipedia. I have used the one found at archive.alwaysmovefast.com/basic-edge-detection-in-python.html. Then convert any grayscale value less than 180 (if you want the boxes darker just increase this value) into black and otherwise make it completely white. Then create bounding boxes, lines where the pixels are all white. If data isn't terribly skewed, then this should work pretty well, otherwise you may need to do more work. See here for the results: http://imm.io/2BLd
Edit2:
Denis, how large is your dataset and how large are the images? If you have thousands of these images, then it is not feasible to manually remove the borders (the red background and yellow bars). I think this is important to know before proceeding. Also, I think the prewitt edge detection may prove more useful in this case, since there appears to be less noise:
The previous method of segmenting may be applied, if you do preprocess to bin in the following manner, in which case you need only count the number of black or white pixels and threshold after some training samples.