How to evaluate the quality of interpolation? [closed] - matlab

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am building a pyramid of images. First I take a big picture and build a smaller one even smaller, etc. I use interpolation to reduce the image. And I need to understand at what interpolation there will be less lost information between images. This is what I mean by interpolation quality.
I am looking at horizontal gradients. Please tell me how good this criterion is or if there is something better.
Blurred = imfilter(img, PSF);
Blurred = im2double(Blurred)
Blurred2 = imresize(Blurred, [300 300], "Method", "bicubic");
[x0,y0] = meshgrid(1:360,1:360);
[x, y] = meshgrid(1:1.2:360, 1:1.2:360);
Blurred3 = interp2(x0, y0, Blurred, x,y, "spline");
gradX = diff(Blurred,1,1);
gradY = diff(Blurred,1,2);
gradX2 = diff(Blurred2,1,1);
gradY2 = diff(Blurred2,1,2);
gradX3 = diff(Blurred3,1,1);
gradY3 = diff(Blurred3,1,2);
[h, cx]=imhist(gradX);
[h2, cx2]=imhist(gradX2);
[h3, cx3]=imhist(gradX3);
h=log10(h);
h2 = log10(h2);
h3 = log10(h3);
figure, plot(cx, h)
hold on
plot(cx2, h2);
plot(cx3, h3);
hold off

You're using the finite difference approximation to the derivative. The units in gradX are intensity units/pixel, with "pixel" the distance between pixels (which is assumed to be 1). When you rescale your image, you increase the pixel size, but in the derivative you're still assuming the distance between pixels is 1. Thus, the values in gradX2 are larger than those in gradX. You'd have to normalize by the image width to correct for this effect.
But still, after normalization, I don't see how this is a measure of quality of the interpolation. The right question would be: how well can I reconstruct Blurred from Blurred2? I'm assuming here that Blurred has been blurred just sufficiently to avoid aliasing when resampling the image.
I would apply a 2nd round of interpolation to Blurred2 to recover an image of the same size as Blurred, then compare the two images using MSE or similar error measure.

Related

Confusion matrix image in matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to make a confusion matrix for some classification problem.
So far, I've managed to make a 10 by 10 matrix that stores the accuracy of my estimation for classification problem.
Now I want to make a 10 by 10 square image(?) that has a darker color when the number in that location of the matrix has a higher number. (Ranges from 0 to 100)
I've never done graphics with Matlab before.
Any help would be greatly appreciated.
Thanks.
I would use image. For example:
img = 100*rand(4,4); % Your image
img = img./100*64; % The `image` function works on scale from 0->64
image(img); % or `image(img')` depending on how you want the axis
colormap('grey'); % For grey scale images
axis equal; % For square pixels
Or for inverted colours you can change the one line to:
img = 64-img./100*64;

To remove blood vessel [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to remove the blood vessel in this images, please suggest any method and want to detect the microaneurysms (the red small dots in the images), below is my images after enhancement :
You could do something like this:
A = imread ('tFKeD.jpg');
C=bwlabel(A);
IM2 = imcomplement(C); % // invert the image so that your objects are 1
se = strel('diamond',3); % // Create a morphological object
BW2 = imdilate(IM2,se);
L=bwlabel(BW2); % // Label your objects
E = regionprops(L,'area'); % // Get the respective area
Area = cell2mat(struct2cell(E)); % // Convert to a matrix
[~,largestObject] = max(Area); % // Find the one with the largest area
vessel = L==largestObject;
imshow(vessel)
I suggest the following approach:
Take a threshold on the input image and keep all the values below the threshold.
This will generate a mask, in which the blood vessels and the microaneurysms are marked in white, and the rest is marked in black.
The threshold value can be determined by using the image histogram.
From looking at the image, it seems that the threshold should be low (due to the fact that the blood vessels and the microaneurysms are relatively dark).
Calculate the connected components in the image using bwconncomp.
Perform noise cleaning on the mask from the previous stage.
This can be done by using morphological operations (such as imclose), or by zeroing out connected components which
are too small to be classified as microaneurysms.
The biggest connected component should represent the blood vessels - remove it from your mask.
The output of this stage will be the desired result.

computing Histogram of oriented gradients on log polar bins [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to compute histogram of oriented gradient on my image. But I don't want to divide the image to regular square blocks. I'm going to divide the image to uniform log polar bins(like bins in shape context or bins like here ) and then on each bin(block) the histogram of gradient with 8 orientation is computed.
But
1) I don't know how to divide the image to log polar bins. Can I use shape context? Or even the above link for partitioning to these bins?
2) how can I compute HOG on this bins since available codes(in matlab, OpenCV and EmguCV) use square bins? I have no idea.
What you are describing sounds pretty much like the C-HOG (circular HOG) features in the original HOG paper. The only difference wrt typical hog is the shape of the bins. I think it would be best to:
iterate over the pixels
calculate the circular bin number for each pixel
add the contribution of the gradient at the pixel to the histogram corresponding to the bin number
A good starting point would be the pseudo-matlab-code in this answer: https://stackoverflow.com/a/10115112/1576602

Image segmentation based upon optical features [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have an image with some texture in a region shown in the first image. I want to segment the image based upon this texture. For this I have extracted feature as shown with blue squares (second image). I want to extract the region bound to the rectangular distribution of the features (shown by red dotted line).
Image 1:
Image 2:
Can somebody help me by suggesting some methodology to pursue this problem. Thanks
This looks like it might fit the GraphCut image segmentation framework:
You want to find a binary assignment per-pixel (1 - this pixel belongs to the foreground, 0 - the pixel is part of the background). This assignment should include as many "texture locations" as possible in the foreground, while preserving "smooth boundaries" between foreground and background.
The smoothness requirement prevents your "ideal" assignment to be 1 for the blue dots and zero everywhere else.
Now, how to search for such a binary assignment using Matlab?
Assume you have img of size H-by-W, and you have detected the locations of the texture features and stored these location in a 2-by-n matrix locs.
Setting the per-element cost:
>> bgCost = zeros( H, W );
>> bgCost( [1 H] * (locs-1) + 1 ) = 1000; %// put 1000 penalty for assigning texture dot to foreground
>> fgCost = 10*ones( H, W ); %// assign some positive penalty for assigning non-texture location to FG - prevent an "all foreground" solution.
>> fgCost( [1 H] * (locs-1) + 1 ) = 0;
Optimization:
>> lambda = 5; %// set relative weight between smoothness term and "texture" term
>> gch = GraphCut('open', cat(3, fgCost,bgCost), lambda * [0 1;1 0],
>> [gch BW] = GraphCut('expand', gch ); %//optimization
>> gch = GraphCut('close', gch ); %//cleanup
You should get a nice binary mask in BW
>> figure;imshow( BW, [] );title('binary mask');
There are three parameters you can play with if you are not satisfied with the result BW:
the cost you assign to texture dots in the background (set to 1000 here).
the cost you assign to non-texture pixels in the foreground (set to 10 here).
the relative strength of the smoothness cost lambda.
Try and change these values and see how they influence the resulting mask.
I use this matlab wrapper for GraphCut optimization.

Segment particles into black/white image [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can someone help me turn this image into a Black and White (not grayscale) image where it particles are black and the background is white? (or visa verse).
It's is not as simple as thresholding the image since the background varies in intensity and subtracting a (gaussian) blurred version does improve the situation but not enough.
best
Markus
I suggest you use high-pass filtering to remove the slow backgroud variations, and then apply a threshold.
I have tried a very simple form of high-pass filter: convolve with constant matrix (this is a low-pass filter) and then remove from original image.
See example result.
im = double(imread('tmp.jpg'));
im = im./max(im(:)); % normalize original image
N = 200; % select N of the order of background color spatial variations
imf = filter2(ones(N)/N^2,im); % normalized low-pass filter
imf = im - imf; % high-pass filter
imf = imf-min(imf(:)); % normalize between 0...
imf = imf/max(imf(:)); % ... and 1
threshold = .4; % select as appropriate
imft = imf < threshold;
imagesc(imft), colormap(gray), axis image