Matlab ROI Image Processing Approach - image

I currently have images of the following nature:
The goal is to have the code display the mean value of each of the squares. The position of each square slightly shifts from image to image. The images are stored as 1024 x 1024 matrices (type = double). Any suggestions on what approach to take in this case?
Thank you for your time!

Related

Image sort with matlab

I am trying to do some kind of image sorting.
I have 5 images and first one is my main image. I am trying to sort images according to their similarity.(Most similar image to less similar image).
Matlab had matchfeature method but I dont think I jave used it correctly because my results are wrong.I try to use:
[indexPairs,matchmetric] = matchFeatures(features1,features2,"MatchThreshold,10")
then i try to sort the matchmetric array.But it didnt work
Can anyone tell me some algorithm or any tips ?Thank you..
You could compute the correlation coefficient between every images and your main image and then sort them based on the coefficient.
doc corr2
For example, let's say you store all your images in a cell array (called ImageCellArray) in which the first image is your "main image":
for i = 2:size(ImageCellArray,2) % size(ImageCellArray,2) is the total # of images, i.e. the size of the cell array containing them.
CorrCoeff(i) = corr2(rgb2gray(ImageCellArray{1}),rgb2gray(ImageCellArray{i}));
end
[values indices] = sort(CorrCoeff); % sort the coefficients and get the number of the corresponging image.
Then you're good to go I guess.
You could compute the PSNR (peak signal-to-noise ratio) for each image compared to the main image. PSNR is a metric commonly used to measure the quality of a reconstructed compression against the original image.
It's implemented in Matlab in the Computer Vision System toolbox as a functional block, and there is also a psnr function in the Image Processing toolbox. The result will be a number in decibels you could use to rank the images. A higher PSNR value indicates greater similarity.
Take a look at this example of image retrieval. Instead of matching the features between pairs of images it uses the KDTreeSearcher from the Statistics Toolbox to find nearest neighbors of each feature from the query image across the whole set of database images.

entropyfilt in OpenCV

I am working on an image processing project and I have to use entopyfilt (from matlab).
I researched and found some information to do it but not enough. I can calculate the entropy value of an image, but I don't know how to write an entropy filter. There is a similar question in the site, but I also didn't understand it.
Can anybody help me to understand entropy filter?
From the MATLAB documentation:
J = entropyfilt(I) returns the array J, where each output pixel contains the entropy value of the 9-by-9 neighborhood around the corresponding pixel in the input image I. I can have any dimension. If I has more than two dimensions, entropyfilt treats it as a multidimensional grayscale image and not as a truecolor (RGB) image. The output image J is the same size as the input image I.
For each pixel, you look at the 9 by 9 area around the pixel and calculate the entropy. Since the entropy calculation is a nonlinear calculation, it is not something you can do with a simple kernel filter. You have to loop over each pixel and do the calculation on a per-pixel basis.

make a mask for each well in a grid

I have a grid of wells in an image and I'm trying to analyze this in Matlab. I want to create a box around each well to use as a mask. The way I am trying to go about this is to find the offset vectors from the X and Y normal and then use that to make a grid since I know the size of the wells.
I can mask out some of the wells but not all of them---but this doesn't matter since I know that there is a well in every position (see here). I can use regionprops to get the centers but I can't figure out how to move to the next step.
Here is an image with the centers I can extract
Some people have suggested that I do an FFT of the image but I can't get it to work. Any thoughts or suggestions would be greatly appreciated. Thanks in advance!
Edit: Here is the mask with the centers from the centroid feature of regionprops.
here's a quick and dirty 2 cents:
First blur and invert the image so that the well lines will have high intensity values vs the rest, and further analysis will be less sensitive to noise:
im=double(imread('im.jpg'));
im=conv2(im,fspecial('Gaussian',10,1),'same');
im2=abs(im-max(im(:)));
Then, take a local threshold using the average intensity around a neighborhood of (more or less) a well size (~200 pixels)
im3=imfilter(im2,fspecial('average',200),'replicate');
im4=im2-im3;
bw=im2bw(im4,0);
Fill holes (or wells):
[bw2,locations] = imfill(bw,'holes');
Remove objects smaller than some size:
bw3 = bwareaopen(bw2, 2000, 8);
imagesc(bw3);
You can take it from there...

Image Cropping with a Matrix Filter

After some processing, I got a black&white mask of a BMP image.
Now, I want to show only the part of the BMP image where it is white in the mask.
I'm a newb with matlab(but I love it), and I've tried a lot of matrix tricks learned from google, well, none works(or I'm not doing them right ..)
Please provide me with some tips.
Thanks for your time in advance.
Assuming the mask is of the same size as image, then you can just do (for grayscale images):
maskedImage=yourImage.*mask %.* means pointwise multiplication.
For color images, do the same operations on the three channels:
maskedImage(:,:,1)=yourImage(:,:,1).*mask
maskedImage(:,:,2)=yourImage(:,:,2).*mask
maskedImage(:,:,3)=yourImage(:,:,3).*mask
Then to visualize the image, do:
imshow(maskedImage,[]);
Using one of the two matlab functions repmat or bsxfun the masking operation can be performed in a single line of code for a source image with any number of channels.
Assuming that your image I is of size M-by-N-by-C and the mask is of size M-by-N, then we can obtain the masked image using either repmat
I2 = I .* repmat(mask, [1, 1, 3]);
or using bsxfun
I2 = bsxfun(#times, I, mask);
These are both very handy functions to know about and can be very useful when it comes to vectorizing your code in general. I would also recommend that you look through the answer to this question: In Matlab, when is it optimal to use bsxfun?

not getting glcm matrix dimensions for 8 bit grayscale image

As theory states, a glcm matrix is said to have dimensions of 2^x by 2^x where x is the grayscale depth of the image. My problem is that I get a 8 by 8 matrix instead of a 2^8 By 2^8 matrix when I run it on a 8 bit grayscale image.
Could someone please help me out?
According to MATLAB documentation,
graycomatrix calculates the GLCM from a scaled version of the image.
By default, if I is a binary image, graycomatrix scales the image to
two gray-levels. If I is an intensity image, graycomatrix scales the
image to eight gray-levels. You can specify the number of gray-levels
graycomatrix uses to scale the image by using the 'NumLevels'
parameter, and the way that graycomatrix scales the values using the
'GrayLimits' parameter — see Parameters.
In short, you need to run the function as follows:
glcm = graycomatrix(I , 'NumLevels' , 2^8 );

Resources