Finding number of quantizing layers in MATLAB - matlab

I'm working on image processing, and I have an image that has been DCT'd and quantized for 8 x 8 blocks of the 512 x 512 matrix, now I have to find how many quantizing levels that the image has. Do I need to take the top left pixel and place it in to an array and then place this on a graph calling hist?

length(unique(x(:))), where x is your image array. This is appropriate for grayscale images.

Related

Matlab - how to calculate image pixels shift

In Matlab, I have two similar images, but one has a pixels shift compare to the other. how can I calculate the the offset (amount of pixels) for axis x and y?
Image Center
Image Shift
The general problem is called image registration. You can use cross-correlation to find the subpixel image registration, for example by the function dftregistration on the file exchange.
To register the two images A and B within 0.1 pixels by specifying an upsampling parameter of 10
A=(imread("img1.png"));
B=(imread("img2.png"));
upsamplingfactor = 10;
output = dftregistration(fft2(A),fft2(B),upsamplingfactor );
disp(output),
0.2584 0.0000 75.5000 -85.5000
We get an image shifted by y=75.5 and x=-85.5 pixels with an uncertainty of 0.258 pixels. This can get more accurate if you process the image before to reduce noise via applying a threshold or blurring)

How do i effectively compare an image with another image whose resolution is double of the original image?

I have two sets of 3D images (they come in form of 2D stacks). Image A is 10 micron, with size: 1000 x 1024 x 1017, while image B is 5 micron, with size: 2004 x 2048 x 2036. I like to make some computations on randomly chosen set of the 2D slices of A, and then compare this to the same set of slices for B. However, since B has twice the number of slices for each slice of A, will it be sensible to compare two slices of B to each of A? If so, how do i determine exactly which of the two slices of B make up a slice of A?
While contemplating on this, i also thought of blowing up A by 2 using imresize function for each 2D slice that i chose for the computation. Will it be okay to compare this new B with the A, considering that i have completely ignored what happens with the z-coordinate?
Thank you.
As you mentioned this is microCT, I am assuming that both images are different size resolution of the same object. This means that pixels have specific spatial location, not only value, therefore for this case, there are no pixels (assuming a pixel is a infinitesimally small dot in the center of the cube) that match in both images.
So, lets assume that in image A, the locations of the pixel centers are their indices (1,1,1), (1,1,2) etc. This means that the image starts (pixel boundaries) at "world value" 0.5, and ends at size(imgA)+0.5
Now, first lets transform the desired pixel coordinates for interpolation to this range. imgB pixel centers are then in locations (ind-0.5)*size(imgA)/size(imgB)+0.5.
Example: Assume
size(imgA,1)=3; size(imgB,1)=4;
therefore the pixels in imgA are at x location 1:3. The pixels on imgB are, using the above formula, in [0.8750 1.6250 2.3750 3.1250].
Note how the first pixel is 0.375 from 0.5 (our image border) and the next pixel is at 0.75 (double 0.375*2).
We scaled a higher resolution image to the same "real world" coordinates.
Now to the real stuff.
We need to create the desired coordinates in the reference (A) image. For that, we do:
[y, x, z]=...
ndgrid((1:size(imgB,1)-0.5)*size(imgA,1)/size(imgB,1)+0.5),...
(1:size(imgB,2)-0.5)*size(imgA,2)/size(imgB,2)+0.5),...
(1:size(imgB,3)-0.5)*size(imgA,3)/size(imgB,3)+0.5);
Now these 3 have the coordinates we want. Caution! each of these are size(imgB) !!! You need to have the RAM 5*size(imgB) in total to work with this.
Now we can interpolate
imAinB=interp3(imgA,x,y,z,'linear'); % Or nearest
It seems to be that your function is imresize3. You can change one volume to the other's dimentions with:
B = imresize3(V,[numrows numcols numplanes])
You can also explore interpolation methods.

divide a picture in blocks of size (10-by-20) in matlab

I have a black and white image . The image is of 280x420 pixels, and each pixel is a value within the interval [0,1]. I want to divide the picture in blocks of size (10-by-20), this will give 28x21 (= 588) blocks.
((In order to create the input vectors, each block should be written
as (200-by-1) vectors, where each column of the blocks has been added
to the previous one. In this way we will have 588 input vectors of size
200.))
How to do that and what code should I use??
thanks

Obtaining the pixel values of gray scale image from a binary image

I do binary thresholding on a 16 bit gray scale image.This would help me in segmenting the region of interest.After binary thresholding,i would like to get the individual pixel intensities which are the intensities of the original 16 bit image and not the binary intensity values say 0,65535...
How can i do this?
Find the region of interest in image segmentation using the binary image. After this, use the pixel locations in the 16 bit image for further processing of the image.
To get a image from your original image, I and a binary (logical) segmented image BW:
I2 = I.*BW;
I2 should have the original values in the ROI and 0 elsewhere. Or, to get just a list of pixels and their values, via logical indexing:
I2 = I(BW);
Alternatively, depending on what you're doing, you may want to use regionprops:
stats = regionprops(BW,I,'MeanIntensity','PixelValues');
For a BW image showing the regions of interest, and a greyscale image I this will return the mean intensity and all list of all pixel values in I for each separate region (defined as a connected areas in BW).

How many slices that the segmented image contains in image segmentation using mat-lab

I need know that how many slices that the segmented image contains in image segmentation using mat-lab And also i want to know the size of single slice
Its hard to know how to answer without more details about the images you are working with. If you have the image processing toolbox, you can load the image with:
IM = imread('your_image.tif');
Once you have your image loaded, you can figure out the size simply by:
size(IM)
For example, if you loaded a RGB image that was 512x512 pixels, the size() output would be (512, 512, 3), indicating that you have 3 planes, each 512 pixels by 512 pixels.