Blurred borders in Cairo - cairo

What is proper way to draw a blurred rectangular border using the Cairo API? I am writing a patch for Shotwell to add a blurred shadow to the thumbnails in the thumbnail view.
For now I am experimenting with manual blurring.

I ended up drawing the border with linear and radial gradients.
Here is a small visualization. The lines symbolize the linear grandients and the 0 the radial gradients.
0
|
|
0------0

Related

How to exclude the transparent parts which are not rectangles when conducting Fourier analyses on PNG images?

Some PNG images have transparent backgrounds. We can get maps of transparent degree from PNG images through imread.
It's easy to exclude the transparent parts in Fourier analysis if they are rectangles. However, how to exclude the transparent parts which are not rectangles in Fourier analysis (using fft2)?
In this case, how to use the maps of transparent degree in conducting Fourier analysis?

Cairo: How to draw a bitmap clamped to edge?

I am setting a source surface and drawing. I am getting a border of the target surface's color at the edges, if the bitmap is stretched.
I believe this is because it is interpolating at the edge with alpha=0. How can I change this so it clamps the interpolation to the colors at the edge of the source texture? This would be equivalent to GL_CLAMP_TO_EDGE in OpenGL.
I found the answer. CAIRO_EXTEND_PAD is what I needed.

how to include a dark border to bright segmented image?

I have an image like this.note that the regions are not perfectly shaped.it is rectangular like region and ellipse like region. I have segmented the ellipse like region using some algorithm.segmented region is bright one.the border (red rectangle) is dark one
finally i must get red rectangular like region
can you suggest any algorithm to perform this
I see that you have done some real progress on your segmentation. Because you already have an idea of the location of elements you want to segment, you should use a watershed with constraints/markers:
Your actual segmentation represents the inner markers.
You dilate it with a big structuring element (bugger than the inter disk space).
You take the contour of the dilation, and that's your outer markers.
You compute the gradient of the original image.
You apply the watershed on the gradient image, using the markers you have just computed.
[EDIT] As the segmentation you provided does not match with the original image (different dimensions), I had to simulate roughly a simple segmentation, using this image (the red lines being the the segmentation you already have). And I got this result.

LED Screen recognition in image using MATLAB

I'm trying to detect the screen border from the image (In need the 4 corners).
This is the Image:
I used HOUGH transform to detect lines and intersection points (the black circles) and this is the result:
Now I need to find the 4 corners or the 4 lines.. everything that will help me to crop the image, What can I do?
Maybe use the screen aspect ratio? but how?
I'm using Matlab.
Thanks.
A naive first approach that would do the trick if and only if you have same image conditions (background and laptop).
Convert your image to HSV (examine that in HSV the image inside the
screen is the only portion of the image with high Saturation, Value
values)
Create a mask by hard thresholding the Saturation and Value channels
Dilate the mask to connect disconnected regions
Compute the convex hull to get the mask boundaries
See a quick result:
Here is the same mask with the original image portion that makes it through the mask:
Here is the code to do so:
img = imread( 'imagename.jpg'); % change the image name
hsv = rgb2hsv( img);
mask = hsv(:,:,2)>0.25 & hsv(:,:,3)>0.5;
strel_size = round(0.025*max(size(mask)));
dilated_mask=imdilate(mask,strel('square',strel_size));
s=regionprops(dilated_mask,'BoundingBox','ConvexHull');
% here Bounding box produces a box with the minimum-maximum white pixel positions but the image is not actually rectangular due to perspective...
imshow(uint8(img.*repmat(dilated_mask,[1 1 3])));
line(s.ConvexHull(:,1),s.ConvexHull(:,2),'Color','red','LineWidth',3);
You may, of course, apply some more sophisticated processing to be a lot more accurate and to correct the convex hull to be just a rectangular shape with perspective, but this is just a 5 minutes attempt just to showcase the approach...

Filling some region with colour, and the rest of the image as black

I have drawn some polygon on an image after using imshow and hold on, and filled it with white as follows:
fill(x(k),y(k),[1 1 1])
How can I make the rest of the image black while keeping the polygon white? In other words, how can I make a binary image, where the polygon is white, and the rest of the image is black? Provided that the polygon is a bit complex.
Thanks.
Use roipoly:
BW = roipoly( I, x(k), y(k) );
Where I is your input image (you only need it to get the desired output size of the binary maxk BW). y and x are the corners of your polygon.