Moving a greyscale image such that the lowest pixel with an intensity above 0 is at the bottom of the image.

2 visualizzazioni (ultimi 30 giorni)
Cyrus N il 28 Giu 2017
Risposto: Image Analyst il 29 Giu 2017
I'm trying to translate a greyscale image such that the bottommost pixel with an intensity>0 is at the bottom of the pic, I already have it such that the left most pixel . My code for translating is as follows: lungc_ref = imref2d(size(c)) [row, column] = find(c, 1, 'first'); [row2 column2] = find(c, 1, 'last'); t = [1 0 0; 0 1 0; -(column-1) (256-row2) 1]; tform = affine2d(t); imwarp(c, tform); [c_translated,lungc_ref] = imwarp(c,tform,'OutputView',lungc_ref); imshow(c_translated, [0 1000])
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposta accettata

Massimo Zanetti il 29 Giu 2017
Modificato: Massimo Zanetti il 29 Giu 2017
Use the circshift function, which shifts arrays along one dimension. Here is an example:
%generate an image (matrix)
A = rand(6,9)
%find linear index of the minimum value
[~,ix] = min(A(:));
%convert linear index into subscript index
[r,c] = ind2sub(size(A),ix)
%shift image rows to put the lowest valued pixel at the bottom
Y = circshift(A,size(A,1)-r,1)
%additionally, you can also shift image columns to put the lowest valued pixel at the left
Y = circshift(Y,size(A,2)-c+1,2)
Check it out.
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Più risposte (2)

Cyrus N il 29 Giu 2017
Alternatively I found that lowestRow = find(sum(one, 2)>0, 1, 'last'); also seems to work for finding the bottom row after which you can subtract the value for lowestRow from the image dimension to affix the bottom row of the grey image to the bottom row of the figure.
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Image Analyst il 29 Giu 2017
Simply figure out how much to move the image, then call imtranslate(). It's different than circshift in that it doesn't wrap the image around to the other side.
Description
B = imtranslate(A,translation) translates image A by the translation vector specified in translation. If A has more than two dimensions and translation is a two-element vector, imtranslate applies a 2-D translation to A, one plane at a time.
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Categorie

Scopri di più su Image Arithmetic in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by