2-D alpha map examples for blending two overlayed images in MATLAB - 2d

I would like to blend two images, one is smaller and is completely enclosed by the larger one, Assume the both are rectangular. I would like to blend these two so that there is a smooth transition in a rectangular band around the smaller image. I am trying to do this in MATLAB.
For example here two images are shown on top of each other, orange and black mages:
I would like to create a transition band around the orange image such that at the very outward boundaries of the band the alpha map for the orange image has a value of 0 and for very inward boundaries have value of 1 and there is a smooth transition from 0 to one inside the gray band that is shown below:
I am looking for a map for the gray area probably a 2-D matrix that has values between 0 and 1. Is there any equation based or ready made such matrix?
I know I can create a simple linear transition for a vertical or horizontal band for example if the X shows the x-coordinate of the left most edge of the inner image and my blending width is W then I can use this:
alpha(x) = (x-X)/W for X<x<X+W
1 for x > X+W
But how to create such an alpha in 2-D?

Related

Scale an SVG object along a user-defined axis in Illustrator

I have an object (see orange arc below) within an SVG that I would like to scale along the axis of the object itself.
I know the "Transform" options in Illustrator allow you to scale along the X or Y axis, but that doesn't work for me. I want to scale the object such that at each cross-section of the arc (depicted as the black lines in the photo), the object is exactly 10% of the width of the original. Therefore, the axis that I want to scale along is the hypothetical curved line which passes perpendicularly through all of the black lines in the photo.
If done correctly, this should reduce the X and Y dimensions of the object only slightly, but will reduce the orange-colored area to be 10% of the original.

DICOM why need overlay and how to read it

Just wondering why we need the overlay and when we will need it?
I have a Scout image with overlay, what do these dots mean and what do these numbers or fractions mean?
How these numbers are drawn on the image?
DICOM standard allows two specific types of overlays (graphics and ROI) along with the image and overlays are stored as 1-bit image in Overlay Data (60XX, 0050) attribute. A dataset can have up to 16 separate overpay planes (using the repeating groups encoding).
The overlay plane that represents region of interest (ROI) will have value of “R” for Overlay Type (60xx, 0040) attribute and ROI Area (60xx, 1301), ROI Mean (60xx,1302) and ROI Standard Deviation (60xx, 1303) can be used for the corresponding values of ROI. All bits representing ROI will have a value of 1 that represents the pixels under the boundaries of the actual image data.
Graphic Overlay will have value of “G” in Overlay Type (60xx, 0040) attribute and it is used for expressing reference marks (reference line), graphic annotation, or bitmap text etc. Again, all visible values in an overlay plane are set to 1.
The Overlay Rows (60xx, 0010) and Overlay Columns (60xx,0011) specifies the width and height of the overlay plane. Overlay Bits Allocated is always 1 and Overlay Bit Position is 0 (it was used in previous version and usage has been retired). Overlay Origin (60xx, 0050) is used to described the first overlay point with respect to the pixel in the image and 1\1 represents upper left pixel of the image.
Overlays can be used to display any data over an image. You could, for example, allow users to make annotations or graphics marks. You cannot mark the original data, so the overlay is stored in a separate layer.
In your case, the creator of the overlay should explain its meaning.
The meaning of the overlay is:
i.e. 2/16 -> Series number 2 and slice number 16

Extract pixel coordinates in scilab

I have extracted edge using image processing then I selected pixel coordinate using xclick of extracted edge.Is this correct or there is need of reverse y axis coordinate?(Extracted edge is white on black background)
I want to automatically extracted pixel coordinates of extracted edge not by mouse selection.Is there is any command available in scilab?(I use canny edge detector and morphological filter to extract edge)
Please give me some suggestions
Thanks
1.) Whether to reverse the y coordinte or not, depends on the further processing. Any coordinate system can be used if you need only relative measurements and the true orientation of your features is not important (e.g. reversing top and bottom makes no difference if you simply want to count objects or droplets). Hovewer if you want to indicate your found features by plotting a dot, or a line, or a rectangle (e.g. with plot2d or xrect) or a number (e.g. with xnumb) over the image, then it's necessary to match the two coordinate sytems. I recommend this second option and to plot your result over the original image, since this is the easiest way to check your results.
2.) Automatic coordinate extraction can be made by the find function: it returns those indices of the matrix, where the expression is true.
IM=[0,0,0,1;0,0,0,1;0,1,1,1;1,1,0,0]; //edge image, edge = 1, background = 0
disp(IM,"Edge image");
[row,col]=find(IM==1); //row & column indices where IM = 1 (= edge)
disp([row',col'],"Egde coordinates (row, col)");
If your "Egde image" marks the edges not with 1 (or 255, pure white pixel) but with a relatively high number (bright pixel), then you can modify the logical expression of the find function to detect pixels with a value above a certain threshold:
[row,col]=find(IM>0.8); //if edges > a certain threshold, e.g. 0.8
EDIT: For your specific image:
Try the following code:
imagefile="d:\Attila\PROJECTS\Scilab\Stackoverflow\MORPHOLOGICAL_FILTERING.jpg";
//you have to modify this path!
I=imread(imagefile);
IM=imcrop(I,[170,100,950,370]); //discard the thick white border of the image
scf(0); clf(0);
ShowImage(IM,'cropped image');
threshold=100; //try different values between 0-255 (black - white)
[row,col]=find(IM>threshold);
imheight=size(IM,"r"); //image height
row=imheight-row+1; //reverse y axes coordinates (0 is at top)
plot2d(col,row,style=0); //plot over the image (zoom to see the dots)
scf(1); clf(1); //plot separate graph
plot2d(col,row,style=0);
If you play with the threshold parameter, you will see how the darker or whiter pixels are found.

Concave quadrilateral from rectangle

Using only CSS, can a quadrilateral with an inner angle that is greater than 180 degrees be created by manipulating a single rectangle? I know that an arbitrary convex quadrilateral can be created from a standard rectangle using CSS3 transformations.
I have been able to create concave polygons using multiple rectangles in several different ways (sometimes with the help of hiding overflow); some combination of:
Adjacent rectangles. This is a problem because visual discrepancies occur at the seams due to anti-aliasing, which is more obvious with a high-contrast background. The effect can be particularly bad when used in conjunction with a rotation (other than a "nice" rotation like 45 degrees). The rectangles also have a maddening tendency to be oddly aligned at various levels of zoom.
Overlapping rectangles, whereby the quadrilateral is composed of the union of the rectangles (the color of each rectangle is the color of the quadrilateral). This is a problem when the color of the quadrilateral uses an alpha channel, because the overlapping area appears darker.
Overlapping rectangles, whereby the quadrilateral is composed of the difference of the rectangles (the color of at least one rectangle is the color of the background). This is a problem when simulating a shadow by drawing the same shape at an offset, because the overlapping area of the foreground "erases" any underlying shadow.
[EDIT] An example of a concave quadrilateral (a kind of "Star Trek" symbol) using #1 and #3 above can be seen here.
I would like to have a concave quadrilateral with a simulated inset shadow (dark foreground color with alpha channel, light shadow color with alpha channel), which is why #2 and #3 above are problematic. An actual shadow seems out of the question at this point; I havent had very good experience with the shadows of tweaked elements.
So, any possibility to do this by manipulating a single rectangle? Or, is there some other way that I haven't considered?
[EDIT]
I think this is possible to a limited degree, but it's kind of a cheat: Use a single-character text whose glyph is already a concave quadrilateral in some reasonably safe font (for example, U+27A4, black rightwards arrowhead in Arial Unicode), then transform the crap out of it. This would have problems for cross-browser alignment with other elements of the page, however.
I'm pretty sure there's not, because while CSS relies on matrix transforms, it's not a free coordinate transform - the box coordinates are contrained via reflections:
If we have a rectangle (p1,p2,p3,p4) with p1 opposite p3 and p2 opposite p4, then the CSS representation of this rectangle is an a shape defined using only three points: p1, p2, p3 and then implied point p4 that is always computed as {p2 reflected over the midpoint of line p1-p3}. Any manipulation of the three real coordinates for the rectangle will lead to a change in the fourth, implied coordinate.
This makes it impossible to get a concave quadrilateral.

Math Problem: Getting Coordinates From Position And Angle

let me begin by stating that's i'm dreadful at math.
i'm attempting to reposition and rotate a rectangle. however, i need to rotate the rectangle from a point that is not 0,0 but according to how far its coordinates has shifted. i'm sure that doesn't make much sense, so i've made some sketches to help explain what i need.
the image above shows 3 stages of the red rectangle moving from 0% to 100%. the red rectangle's X and Y coordinates (top left of the red rectangle) only moves a percentage of the blue rectangle's height.
the red rectangle can rotate. focusing only on the middle example ("Distance -50%") from above, where the red rectangle is repositioned at -50 of the blue rectangle's height, its new angle in the above image is now -45º. it has been rotated from its 0, 0 point.
now, my problem is that i want its rotational point to reflect its position.
the red and blue rectangles are the same size, but have opposite widths and heights. since the red rectangle's 0,0 coordinates are now -50% of the blue rectangle's height, and since they have opposite widths and heights, i want the rotational point to be 50% of the red rectangle's width (or 50% of the blue rectangle's height, which is the same thing).
rather than specifically telling the red rectangle to rotate at 50% of its width, in order to do what i want, i need to emulate doing so by using a formula that will position the red rectangle's X and Y coordinates so that its rotational point reflects its position.
Here's an illustrated solution to your problem:
I don't exactly understand what you need, but it seems that a procedure to rotate a rectangle around an arbitrary point may help.
Suppose we want to rotate a point (x,y) d radians around the origin (0,0). The formula for the location of the rotated point is:
x' = x*cos(d) - y*sin(d)
y' = x*sin(d) + y*cos(d)
Now we don't want to rotate around the origin, but around a given point (a,b). What we do is first move the origin to (a,b), then apply the rotation formula above, and then move the origin back to (0,0).
x' = (x-a)*cos(d) - (y-b)*sin(d) + a
y' = (x-a)*sin(d) + (y-b)*cos(d) + b
This is your formula for rotating a point (x,y) d radians around the point (a,b).
For your problem (a,b) would be the point halfway on the right side of the blue rectangle, and (x,y) would be every corner of the red rectangle. The formula gives (x',y') for the coordinates of the corners of rotated red rectangle.
It's quite simple really.
1. Let's settle on your point you want to rotate the rectangle about, i.e. the point of rotation (RP) which does not move when you swivel your rectangle around. Let's assume that the point is represented by the diamond in the figure below.
2. Translate the 4 points so that RP is at (0,0). Suppose the coordinates of that point is (RPx,RPy), therefore subtract all 4 corners of the rectangle by those coordinates.
3. Rotate the points with a rotation matrix (which rotates a point anticlockwise around the origin through some angle which is now the point of rotation thanks to the previous translation):
The following figure shows the rectangle rotated by 45° anticlockwise.
4. Translate the rectangle back (by adding RP to all 4 points):
I assume this is what you want :)
It seems like you could avoid a more complex rotation by more crafty positioning initially? For example, in the last example, position the red box at "-25% Blue Height" and "-25% Red Height" -- if I follow your referencing scheme -- then perform the rotation you want.
If you know the origin O and a point P on the side of rotated rectangle, you can calculate the vector between the two:
(source: equationsheet.com)
You can get the angle between the vector and the x-axis by taking the dot product with this vector:
(source: equationsheet.com)
Given this, you can transform any point on the rectangle by multiplying it by a rotation matrix:
(source: equationsheet.com)

Resources